wstrange / asn1lib

Dart ASN1 Encoder / Decoder
BSD 2-Clause "Simplified" License
30 stars 30 forks source link

ASN1Object.preEncoded is broken #39

Closed ThomasKliszowski closed 4 years ago

ThomasKliszowski commented 4 years ago

I tried to implement OPTIONAL tagging on a sequence by doing something like that:

ASN1Sequence()
  ..add(ASN1Integer.fromInt(1))
  ..add(ASN1Integer(privateKey.d, tag: OCTET_STRING_TYPE))
  ..add(ASN1Object.preEncoded(
      160,
      ASN1ObjectIdentifier.fromComponentString("1.2.840.10045.3.1.7")
          .encodedBytes))
  ..add(ASN1Object.preEncoded(
      161, ASN1BitString(publicKey.Q.getEncoded(false)).encodedBytes));

This code gives me a wrong object identifier 1.2.840.10045.3.0.0. After investigate a bit, I could find that ASN1Object.preEncoded() is broken, the range is going from start to length, when it should go from start to start + length.