BER encoding X.690
1 ber encoding
1.1 encoding structure
1.2 identifier octets
1.2.1 types
1.2.2 encoding
1.2.3 long form
1.3 length octets
1.3.1 definite form
1.3.2 indefinite form
1.4 contents octets
ber encoding
the format basic encoding rules specifies self-describing , self-delimiting format encoding asn.1 data structures. each data element encoded type identifier, length description, actual data elements, and, necessary, end-of-content marker. these types of encodings commonly called type-length-value or tlv encodings. format allows receiver decode asn.1 information incomplete stream, without requiring pre-knowledge of size, content, or semantic meaning of data.
encoding structure
the encoding of data consist of 4 components appear in following order:
the end-of-contents octets optional , used if indefinite length form used. contents octet may omitted if there no content encode in null type.
identifier octets
types
data (especially members of sequences , sets , choices) can tagged unique tag number (shown in asn.1 within square brackets []) distinguish data other members. such tags can implicit (where encoded tlv tag of value instead of using base type tlv tag) or explicit (where tag used in constructed tlv wraps base type tlv). default tagging style explicit, unless implicit set @ asn.1 module-level. such tags have default class of context-specific, can overridden using class name in front of tag.
the encoding of choice value same encoding of value of chosen type. encoding may primitive or constructed, depending on chosen type. tag used in identifier octets tag of chosen type, specified in asn.1 definition of chosen type..
the following tags native asn.1:
encoding
the identifier octets encode element type asn.1 tag, consisting of class , number, , whether contents octets represent constructed or primitive value. note types can have values either primitive or constructed encodings. encoded 1 or more octets.
in initial octet, bit 6 encodes whether type primitive or constructed, bit 7–8 encode class of type, , bits 1–5 encode tag number. following values possible:
long form
where identifier not universal, tag number may large 5-bit tag field, encoded in further octets.
the initial octet encodes class , primitive/constructed before, , bits 1–5 1. tag number encoded in following octets, bit 8 of each 1 if there more octets, , bits 1–7 encode tag number. tag number bits combined, big-endian, encode tag number. least number of following octets should encoded; is, bits 1–7 should not 0 in first following octet.
length octets
there 2 forms of length octets: definite form , indefinite form.
definite form
this encodes number of content octets , used if type primitive or constructed , data available. there short form , long form, can encode different ranges of lengths. numeric data encoded unsigned integers least significant bit first (to right).
the short form consists of single octet in bit 8 0, , bits 1–7 encode length (which may 0) number of octets.
the long form consist of 1 initial octet followed 1 or more subsequent octets, containing length. in initial octet, bit 8 1, , bits 1–7 (excluding values 0 , 127) encode number of octets follow. following octets encode, big-endian, length (which may 0) number of octets.
indefinite form
this not encode length @ all, content octets finish @ marker octets. applies constructed types , typically used if content not available @ encoding time.
it consists of single octet, in bit 8 1, , bits 1–7 0. then, 2 end-of-contents octets must terminate content octets.
contents octets
the contents octets encode element data value.
note there may no contents octets (hence, element has length of 0) if existence of asn.1 object, or emptiness, noted.
for example, case asn.1 null value.
Comments
Post a Comment