Skip to content

Commit

Permalink
Merge pull request #95 from famedly/master
Browse files Browse the repository at this point in the history
feat: Add optional ECDomainParameters to ec key from bytes method
  • Loading branch information
Ephenodrom committed Jun 27, 2023
2 parents 0719951 + eecdb4f commit 0776202
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/src/CryptoUtils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ class CryptoUtils {
/// Supports SEC1 (<https://tools.ietf.org/html/rfc5915>) and PKCS8 (<https://datatracker.ietf.org/doc/html/rfc5208>)
///
static ECPrivateKey ecPrivateKeyFromDerBytes(Uint8List bytes,
{bool pkcs8 = false}) {
{bool pkcs8 = false, ECDomainParameters? parameters}) {
var asn1Parser = ASN1Parser(bytes);
var topLevelSeq = asn1Parser.nextObject() as ASN1Sequence;
var curveName;
Expand Down Expand Up @@ -722,13 +722,17 @@ class CryptoUtils {
x = privateKeyAsOctetString.valueBytes!;
}

return ECPrivateKey(osp2i(x), ECDomainParameters(curveName));
return ECPrivateKey(
osp2i(x),
parameters ?? ECDomainParameters(curveName),
);
}

///
/// Decode the given [bytes] into an [ECPublicKey].
///
static ECPublicKey ecPublicKeyFromDerBytes(Uint8List bytes) {
static ECPublicKey ecPublicKeyFromDerBytes(Uint8List bytes,
{ECDomainParameters? parameters}) {
if (bytes.elementAt(0) == 0) {
bytes = bytes.sublist(1);
}
Expand Down Expand Up @@ -759,7 +763,7 @@ class CryptoUtils {
}
var x = pubBytes.sublist(1, (pubBytes.length / 2).round());
var y = pubBytes.sublist(1 + x.length, pubBytes.length);
var params = ECDomainParameters(curveName);
var params = parameters ?? ECDomainParameters(curveName);
var bigX = decodeBigIntWithSign(1, x);
var bigY = decodeBigIntWithSign(1, y);
var pubKey = ECPublicKey(
Expand Down

0 comments on commit 0776202

Please sign in to comment.