diff --git a/lib/src/crypto/aa_pubkey.dart b/lib/src/crypto/aa_pubkey.dart index d4791a7..613111f 100644 --- a/lib/src/crypto/aa_pubkey.dart +++ b/lib/src/crypto/aa_pubkey.dart @@ -28,26 +28,29 @@ class AAPublicKey { AAPublicKeyType get type => _type; + /// Parses AAPublicKey from [encPubKey] bytes which should be DER encoded ASN.1 bytes. + /// + /// Throws [Exception] when provided bytes doesn't contain correct DER encoded ASN.1 AAPublicKey format. AAPublicKey.fromBytes(final Uint8List encPubKey) : _encPubKey = encPubKey { // Parse key type and SubjectPublicKey bytes final tvPubKeyInfo = TLV.decode(encPubKey); if (tvPubKeyInfo.tag.value != 0x30) { // Sequence - throw EfParseError( + throw Exception( "Invalid SubjectPublicKeyInfo tag=${tvPubKeyInfo.tag.value.hex()}, expected tag=30" ); } final tvAlg = TLV.decode(tvPubKeyInfo.value); if (tvAlg.tag.value != 0x30) { // Sequence - throw EfParseError( + throw Exception( "Invalid AlgorithmIdentifier tag=${tvAlg.tag.value.hex()}, expected tag=30" ); } final tvAlgOID = TLV.decode(tvAlg.value); if (tvAlg.tag.value != 0x06) { // OID - throw EfParseError( + throw Exception( "Invalid Algorithm OID object tag=${tvAlgOID.tag.value.hex()}, expected tag=06" ); } @@ -59,7 +62,7 @@ class AAPublicKey { _subPubKeyBytes = tvPubKeyInfo.value.sublist(tvAlg.encodedLen); if (_subPubKeyBytes[0] != 0x03) { // Bit String - throw EfParseError( + throw Exception( "Invalid SubjectPublicKey object tag=${_subPubKeyBytes[0].hex()}, expected tag=03" ); } diff --git a/lib/src/lds/df1/efdg15.dart b/lib/src/lds/df1/efdg15.dart index a44e8fd..280ee4d 100644 --- a/lib/src/lds/df1/efdg15.dart +++ b/lib/src/lds/df1/efdg15.dart @@ -3,7 +3,7 @@ import 'dart:typed_data'; import 'dg.dart'; -import '../../crypto/aa_pubkey.dart'; +import 'package:dmrtd/dmrtd.dart'; class EfDG15 extends DataGroup { static const FID = 0x010F; @@ -26,6 +26,10 @@ class EfDG15 extends DataGroup { @override void parseContent(final Uint8List content) { - _pubkey = AAPublicKey.fromBytes(content); + try { + _pubkey = AAPublicKey.fromBytes(content); + } on Exception catch(e) { + throw EfParseError("Failed to parse AAPublicKey from EF.DG15: $e"); + } } }