Data Structure
ASN.1 - Abstract Syntax Notation One
ASN.1 is a language to describe data structure.
There are different data types: primitiv (boolean, integer, UTF8 string) and constructed (sequence).
e.g.
Sequence
{
Name::= UTF8 String
Age::= Integer
Vegetarian::= Boolean OPTIONAL
Smoker::= [0] Boolean OPTIONAL
}
Sequence
{
Name::= "Müller"
Age::= "30"
Vegetarian::= "false"
Smoker::= "false"
}
TLV - [T]ag [L]ength [V]alue
To encode the ASN.1 data we use the TLV Structure. Every data object consists of a tag, a length byte and the value/data.
The tag defines if the object is an integer, boolean or something else.
Tag 30 : Sequence OC : UTF8 String 02 : Integer 01 : Boolean
Here we have the ASN.1 example encodet to the TLV structure: 30 11 OC 06 4D 7E 6C 6C 65 72 02 01 1E 01 01 00 80 01 00 Legend/Explanation Tag Length Value 30 11 Sequence with a length of 17 OC 06 4D 7E 6C 6C 65 72 UTF8 String with a length of 6 and the value Müller 02 01 1E Integer with a length of 1 and the value 30 01 01 00 Optional Boolean with a length of 1 and the value false 80 01 00 Optional Boolean with a length of 1 and the value false
Coding of the Tag
| b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | explanation |
| 0 | 0 | universal class | ||||||
| 0 | 1 | application class | ||||||
| 1 | 0 | context specific class | ||||||
| 1 | 1 | private class | ||||||
| 0 | primitiv data object | |||||||
| 1 | constructed data object | |||||||
| x | x | x | x | x | tag value | |||
| 1 | 1 | 1 | 1 | 1 | there is a 2nd byte with tag value |
