Skip to content

Commit

Permalink
fix: parsing certificates containing GeneralizedTime (pull request #21
Browse files Browse the repository at this point in the history
…from adamgillmore)

Fixed exception when parsing certificates containing GeneralizedTime
  • Loading branch information
rbellens authored Nov 4, 2022
2 parents a5bbd73 + 190321c commit 850c55f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ dynamic toDart(ASN1Object obj) {
if (obj is ASN1OctetString) return obj.stringValue;
if (obj is ASN1PrintableString) return obj.stringValue;
if (obj is ASN1UtcTime) return obj.dateTimeValue;
if (obj is ASN1GeneralizedTime) return obj.dateTimeValue;
if (obj is ASN1IA5String) return obj.stringValue;
if (obj is ASN1UTF8String) return obj.utf8StringValue;

Expand Down
Binary file added test/files/generalized_time.der
Binary file not shown.
12 changes: 12 additions & 0 deletions test/x509_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,16 @@ MIIIHzCCB8WgAwIBAgIJf35N0O0if7S5MAoGCCqGSM49BAMCMIGwMT8wPQYDVQQDDDZFQURUcnVzdCBF
expect(pi.toString(), expectStr);
});
});

group('Certificate fields', () {
test('Parse Generalized time', () {
var f = File('test/files/generalized_time.der');
var bytes = f.readAsBytesSync();
var parser = ASN1Parser(bytes);
expect(parser.hasNext(), isTrue);

var c = X509Certificate.fromAsn1(parser.nextObject() as ASN1Sequence);
expect(c, isA<X509Certificate>());
});
});
}

0 comments on commit 850c55f

Please sign in to comment.