Data Structure
ASN.1 - Abstract Syntax Notation One
ASN.1 is a formal language to describe data structures. It consists of primitive data objects (boolean, integer, UTF8 string) that can be constructed to define more complex data structures (Sequences, Sets).
e.g.
Record ::= SEQUENCE { Name::= UTF8 String Age::= Integer Vegetarian::= Boolean OPTIONAL Smoker::= [0] Boolean OPTIONAL }
Based on ASN.1, instances of data structures can be defined:
Record { Name::= "Möller" Age::= "30" Vegetarian::= "false" Smoker::= "true" }
TLV - [T]ag [L]ength [V]alue
To encode ASN.1 instances in a computer readable form, a notation called TLV is used.
Every data object consists of a tag, a length byte and the value/data.
The tag defines, for example, 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 from above encoded as TLV structure: 30 11 OC 06 4D 7E 6C 6C 65 72 02 01 1E 01 01 00 80 01 00 which means Tag Length Value 30 11 Sequence with a length of 17 bytes OC 06 4D 7E 6C 6C 65 72 UTF8 String with a length of 6 bytes and the value Möller 02 01 1E Integer with a length of 1 and the value 30 01 01 00 Optional Boolean with the value false 80 01 FF Optional Boolean with the value true
Coding of the Tag
b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | Meaning |
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 | tag continoues on a 2nd byte |