ASN1 Structure Encoding

1.3k views Asked by At

Whether it is allowed in ASN Rules , One ASN structure having Octet string Pointing to Another ASN structure. I'm not able to decode in this context, but One ASN structure having Octet string Pointing to local structure (NON_ASN).

1

There are 1 answers

2
Ethan On

Yes, this is perfectly valid.

There are two ways it's usually done: by constraint, and by convention. The "right" way to do this is by constraint, but it's often done by convention.

ASN.1 calls these contents constraints and uses the CONTAINING keyword to denote them, like this:

S ::= SEQUENCE {
   name    UTF8String,
   age     INTEGER
}

O ::= OCTET STRING (CONTAINING S)

See ITU-T X.682, ยง11 for further details.

The octet (or bit) string thus encoded is encoded with the wrapper appropriate for the encoding rules. Suppose for example that we wanted to encode s S ::= { name "Calvin", age 5 } within the octet string using BER:

The SEQUENCE is encoded in a TLV like this:

0x30 0x0b (UNIV 15, CONSTRUCTED, length 11)
   0x0c 0x06 0x43 0x61 0x6c 0x76 0x69 0x63 (UNIV 13, length 6, "Calvin")
   0x02 0x01 0x05 (UNIV 2, length 1, 5)

This sequence will be wrapped into an additional TLV for the octet string:

0x04 0x0d (UNIV 4, length 13)
   [TLV for S]

Regardless of whether a contents constraint is used or not, the encoding is identical. The contents constraint standardizes the protocol and allows tools to validate and parse messages properly.