ASN.1 Made Simple — Encoding Rules

ASN.1 has sets of rules precisely specifying how messages must be "encoded" for communication with other machines. Each set of "encoding rules" has specific characteristics, such as compactness or decoding speed, which make it best suited for particular environments. Note that all of the encoding rules are able to represent any messages you would like to exchange.

BER, DER, CER

The oldest encoding rule, BER (BASIC ENCODING RULES), uses a Tag-Length-Value (TLV) format for encoding all information. BER always sends a tag to indicate what kind of data follows, then a length indicating the length of the data that follows, then the value which is the actual data. Two related encoding rules, DER (DISTINGUISHED ENCODING RULES) and CER (CANONICAL ENCODING RULES) are subsets of BER which eliminate some of the extra flexibility provided by BER. Note that DER is commonly used in security-related applications such as X.509 digital certificates.

PER

The most compact of the encoding rules is PER (PACKED ENCODING RULES). PER differs from BER in that PER does not send the Tag of the TLV since the order in which components of the message occur is known. PER also does not send the Length of the TLV if the Value has a fixed length. PER also uses additional information from the ASN.1 message description to eliminate redundant information from the Value portion of the TLV, thus making PER messages quite compact and suitable for environments in which bandwidth conservation is important. There are two ways to encode messages in PER - Aligned and Unaligned. With the Aligned PER, a field can be aligned to 8-bit octet boundaries by inserting padding bits. With the Unaligned PER, pad bits are never inserted between fields. Unaligned PER is commonly used in 3GPP cellular technologies such as UMTS (3G) or LTE (4G) for protocols like RANAP, NBAP or RRC.

XER, E-XER

The least compact of the encoding rules, XER (XML ENCODING RULES), uses a textual XML format for its encodings of the form <start-tag> value <end-tag>. The XER and E-XER (Extended XER) differ in that the default encodings produced by E-XER are more suitable for exchanging information with XML Schema Definition (XSD) engines. Note that the same ASN.1 specification can be used with multiple encoding rules, which means that a PER message from a cell phone could be converted to E-XER for display and manipulation in a web browser.