diff --git a/lib/src/extension/uint8list_apis.dart b/lib/src/extension/uint8list_apis.dart index 858ebcf..6ae1e44 100644 --- a/lib/src/extension/uint8list_apis.dart +++ b/lib/src/extension/uint8list_apis.dart @@ -11,4 +11,16 @@ extension Uint8ListEncodeApis on Uint8List { String hex() { return conv.hex.encoder.convert(this); } -} \ No newline at end of file +} + +extension Uint8ListDecodeApis on Uint8List { + DateTime toDate() { + // The date is in the format 'CCYYMMDD' + int century = ((this[0] >> 4) * 10 + (this[0] & 0x0F)) * 100; + int year = (this[1] >> 4) * 10 + (this[1] & 0x0F); + int month = (this[2] >> 4) * 10 + (this[2] & 0x0F); + int day = (this[3] >> 4) * 10 + (this[3] & 0x0F); + + return DateTime(century + year, month, day); + } +} diff --git a/lib/src/lds/df1/efdg11.dart b/lib/src/lds/df1/efdg11.dart index cd98546..7dfae81 100644 --- a/lib/src/lds/df1/efdg11.dart +++ b/lib/src/lds/df1/efdg11.dart @@ -86,14 +86,16 @@ class EfDG11 extends DataGroup { final tlv = TLV.fromBytes(content); if (tlv.tag != tag) { throw EfParseError( - "Invalid DG11 tag=${tlv.tag.hex()}, expected tag=${TAG.value.hex()}"); + "Invalid DG11 tag=${tlv.tag.hex()}, expected tag=${TAG.value.hex()}", + ); } final data = tlv.value; final tagListTag = TLV.decode(data); if (tagListTag.tag.value != TAG_LIST_TAG) { throw EfParseError( - "Invalid version object tag=${tagListTag.tag.value.hex()}, expected version object with tag=5c"); + "Invalid version object tag=${tagListTag.tag.value.hex()}, expected version object with tag=5c", + ); } var tagListLength = tlv.value.length; int tagListBytesRead = tagListTag.encodedLen; @@ -113,7 +115,10 @@ class EfDG11 extends DataGroup { _otherNames.add(utf8.decode(uvtv.value)); break; case FULL_DATE_OF_BIRTH_TAG: - _fullDateOfBirth = String.fromCharCodes(uvtv.value).parseDate(); + _fullDateOfBirth = + uvtv.value.length == 4 + ? uvtv.value.toDate() + : String.fromCharCodes(uvtv.value).parseDate(); break; case PLACE_OF_BIRTH_TAG: _placeOfBirth.add(utf8.decode(uvtv.value));