Decoding nested ASN.1 sequences with implicit tags #2080
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
An ASN.1 parser cannot (in the general case) resolve a tag without external information. Especially implicit tagging requires to be told, at parse-time, what the correct tag actually is (implicit tagging elides the original tag). Parsing isn't really complete until all tagging has been resolved. Example of "completing parsing" in this case: You'll see that this reconstructs the two different sequences correctly. BTW, the two instances of DLTaggedObject are not the same: see the different values for I suggest you don't think of ASN1TaggedObject (and subclasses) as part of the data at all. Add them only when encoding and always resolve them as part of parsing (and don't blindly interpret the 'obj' field as the actual value). If you are designing your own data formats here, I would suggest creating actual data types following the many examples of such in the library. You may also find that the small space savings from implicit tagging are not worth the extra confusion (YMMV). |
Beta Was this translation helpful? Give feedback.
An ASN.1 parser cannot (in the general case) resolve a tag without external information. Especially implicit tagging requires to be told, at parse-time, what the correct tag actually is (implicit tagging elides the original tag). Parsing isn't really complete until all tagging has been resolved.
Example of "completing parsing" in this case:
var obj = encodeDecode("seq.der", SEQ);
var tag = ASN1TaggedObject.getInstance(encoded, BERTags.CONTEXT_SPECIFIC, 1); // Tag validation
var seq = ASN1Sequence.getInstance(tag, false); // ASN.1 types should usually provide a getInstance method like this
You'll see that this reconstructs the two different sequences correctly.
BTW, the two instances of DL…