lapo-luchini / asn1js

JavaScript generic ASN.1 parser
ISC License
576 stars 161 forks source link

Fail to decode OCTET STRING starting with '04' #47

Closed leeopop closed 2 years ago

leeopop commented 2 years ago

Definition

When an octet string's first word starts with '04', the parent octet string becomes the same value to its child.

Example

BCAEHuTjt+01DMJNA05DbZocsVux4yjTcGL7guhGGKsKPA==

Screenshots

image

lapo-luchini commented 2 years ago

I agree that while showing the "potentially included (correctly decoded) child" (useful because many ASN.1 structures use OCTET STRINGs and BIT STRINGs to actually embed more ASN.1 content), the "value" of the base node should be the complete content, not only the child's content, which is the correct value if and only if the parent has the "constructed" bit.

PS: more exactly this only happens if it begins with 041E or, rather, if the content is a valid BER content. You can check that 041D and 041F both don't show the encapsulated child.

leeopop commented 2 years ago

Thank you for your super fast response! I was extracting hash value of a TSInfo document and this rarely happened when the hash starts with specific values. I had a workaround solution that if an entry is surely represents a hash value, I extract the raw bytes and skip the header values. Anyway, the content() representation of this library is very useful to deal with ASN.1 documents which is not as famous as X.509. Thanks again to your fast response and contributing this library to the community!