ASN.1 ===== _Abstract Syntax Notation One_ (ASN.1) allows defining data structures that can be serialized and deserialized in a cross-platform way. _Basic Encoding Rules_ (BER) specify a self-describing and self-delimiting format for encoding ASN.1 data structures. _Distinguished Encoding Rules_ (DER) is a restricted variant of BER thas is unequivocal. DER is a _tag-length-value_ (TLV) encoding: - tag (two forms): - _low-tag-number form_: One octet. Bits 8 and 7 specify the class, bit 6 has value 0 indicating that the encoding is primitive, and bits 5-1 give the tag number. - _high-tag-number form_: Two or more octets. First octet is as in low-tag-number form, except that bits 5-1 all have value 1 Second and following octets give the tag number, base 128, most significant digit first, with as few digits as possible, and with the bit 8 of each octet except the last set to 1. If bit 6 has value 1, it indicates that the encoding is constructed. - length (two forms): - _Short form_: One octet. Bit 8 has value 0 and bits 7-1 give the length. - _Long form_: Two to 127 octets. Bit 8 of first octet has value 1 and bits 7-1 give the number of additional length octets. Second and following octets give the length, base 256, most significant digit first. - value: actual value as byte array of defined length. Class encodings: | Class | Bit 8 | Bit 7 | |------------------|-------|-------| | universal | 0 | 0 | | application | 0 | 1 | | context-specific | 1 | 0 | | private | 1 | 1 | References ---------- - [Go asn1 package] - [A Layman's Guide to a Subset of ASN.1, BER, and DER] [Go asn1 package]: https://golang.org/pkg/encoding/asn1/ [A Layman's Guide to a Subset of ASN.1, BER, and DER]: http://luca.ntop.org/Teaching/Appunti/asn1.html