ASN.1 Types and Tags

Table of contents

  1. Definition
  2. Reference
  3. Deep Dive

Definition

To ensure that encodings are not ambiguous, every ASN.1 type is associated with a tag. A tag consists of two parts: the class and the number as we saw at 3_Tag Length Value chapter. TLV encoding may be recursive (netest construction, constructed format). One value field can consist of one or more other TLVs, which are encoded. No maximum level of nesting is defined, so complex structures can be created. The porperty of Tag is unique. However, the same tag to two (or more) can be assigned to different types, but should avoid ambiguity. The context in which an instance of the type occurs must be sufficient to allow unique identification.

Reference

Please refer to the listed reference below. That help you understand what is ASN.1.

Deep Dive

  1. Tyeps and Tags
    • Let’s take a look at the table below. We cna figure out which tag corresponds to a type, and they are defined by ASN.1.

      TypeTag (dec)TypeTag (dec)TypeTag (dec)
      Bit String03GraphicString25SET17
      BMPString30IA5String22SET OF17
      BOOLEAN01INTEGER02TeletexString20
      CHARACTER STRING29NULL05T61String20
      CHOICE NumericString18TIME14
      DATE31ObjectDescriptor07TIME OF DAY32
      DATE-TIME33OBJECT IDENTIFIER06UniversalString28
      DURATION34OCTET STRING04UTCTime23
      EMBEDDED PDV11PrintableString19UTF8String12
      ENUMERATED10REAL09VideotexString21
      EXTERNAL08RELATIVE-OID13VisibleString26
      GeneralString27SEQUENCE16  
      GeneralizedTime24SEQUENCE OF16  
    • As an example, if we use Universal Class, Primitive TLV, and Tag 03, then the tag field value will be 00h + 0h + 03h = 0x03.
    • Let’s take a look at a couple of tag. The details and more information can be found at ASN1 Tyep and Tag
  2. Bit String (Tag: 0x03)
    • The corresponding Value field to ASN.1 BIT STRING type is arbitrary length strings of bits.
    • The Value field contains a leading byte that specifies the number of bits left unused in the final byte of content.
    • For example, In [Pic.2], the last 5 bits are not used.


    [Pic.2] Bit String Example

  3. Octet String (Tag: 0x04)
    • Octet String is similar to Bit String data types. But one difference is Octet String cannot have unused bits.
    • The leading bytes must not be added to the contents.
    • Example is shown in [Pic.3].


    [Pic.3] Octet String Example

  4. Boolean (Tag: 0x01)
    • The value of type Boolean can be TRUE(0x00) or FALSE(0xFF).
    • The example is shown in [Pic.4].


    [Pic.4] Boolean Example

  5. Integer (Tag: 0x02)
    • The value of integer contains the encoded integer if it is positive, or its two’s complement if it is negative.
    • If the integer is positive but the high order bit is set to 1, a leading 0x00 is added to the content to indicate that the number is not negative.
    • The example is shown in [Pic.5].


    [Pic.5] Integer Example

  6. Object Identifier (Tag: 0x06)
    • Object Identifier is composed of the combination of number and dot.
    • The type of Object Identifier is listed in Object Identifier of ASN1.
    • As an example, Object Identification will be written with 1.2.840.113549.1.7.1
    • We will see the Encoding/Decoding rule of Object Identifier in 5_ASN1_ObjectIdentifier chapter in detail, because they are not attached to certificate as the plan form.


    [Pic.6] Object Identifier Example