Skip to content

Fix birthdate conversion issue in EFDG11 #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/src/extension/uint8list_apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,16 @@ extension Uint8ListEncodeApis on Uint8List {
String hex() {
return conv.hex.encoder.convert(this);
}
}
}

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);
}
}
11 changes: 8 additions & 3 deletions lib/src/lds/df1/efdg11.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down