Question

I am finding a lot of contradicting information regarding the tag value for the SEQUENCE (OF) ASN.1 datatype:

Wikipedia claims it is both 0x10 and 0x30:

http://en.wikipedia.org/wiki/Abstract_Syntax_Notation_One -> 0x30

http://en.wikipedia.org/wiki/Basic_Encoding_Rules -> 0x10

According to Microsoft it is 0x30:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb540799%28v=VS.85%29.aspx

And in the Bouncycastle sources one can find:

public const int Sequence = 0x10;

So it is basically a tie between 0x10 and 0x30. Do you know that the real value is or am I missing something?

Was it helpful?

Solution

A BER encoded "tag" is made up of several bit fields:

---------------------------------
| 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
---------------------------------
|Class  |P/C| Tag Number        |
---------------------------------
  • The tag number for a Sequence(in the Universal Class) is 0x10.
  • A sequence is a Constructed type, making the P/C bit 1
  • Universal Class is 0
  • This makes the entire octet 0x30

Note that there's many ways to encode a sequence in BER/DER/CER, it depends on the exact ASN.1 used. e.g. some protocol might override the class and specify a sequence as Application Specific class, and/or it might specify its own Tag Number if Implicit tagging is used.

You can read the BER encoding spec here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top