ASN.1 Reference Card

ASN.1 Reference Card

 

Obsolete, not commonly used or deprecated syntax is greyed out below

Object Identifier Values

oid1 OBJECT IDENTIFIER ::= {iso standard 2345 modules (0) basic-types (1)}
oid2 OBJECT IDENTIFIER ::= {joint-iso-itu-t ds(5)}
oid3 OBJECT IDENTIFIER ::= { oid2 modules(0) }
oid4 OBJECT IDENTIFIER ::= { oid3 basic-types(1) }
oid5 OBJECT IDENTIFIER ::= { 2 5 0 1 } -- equals oid4

Object identifier value Meaning
{ 1 2 } ISO member bodies
{ 1 2 840 } US (ANSI)
{ 1 2 840 113549 } RSA Data Security, Inc.
{ 1 2 840 113549 1 } RSA Data Security, Inc. PKCS
{ 2 5 } directory services (X.500)
{ 2 5 8 } directory services-algorithms

 

TYPES

Basic Types


BOOLEAN
INTEGER
BIT STRING
OCTET STRING
OBJECT IDENTIFIER
REAL
ENUMERATED

SEQUENCE
SEQUENCE OF
CHOICE

UTF8String
NumericString
IA5String
VisibleString

DATE
TIME-OF-DAY
DATE-TIME
DURATION





*occupies two octets

Tag

dec/hex
[01/01]
[02/02]
[03/03]
[04/04]
[06/06]
[09/09]
[10/0A]

[16/10]
[16/10]
----

[12/0C]
[18/12]
[22/16]
[26/1A]

[31/ *]
[32/ *]
[33/ *]
[34/ *]

Other Types


ObjectDescriptor

EXTERNAL
EMBEDDED PDV

OID-IRI
RELATIVE-OID-IRI

SET
SET OF

UTCTime
GeneralizedTime

PrintableString
T61String
VideotexString
GraphicString
GeneralString
UniversalString
CHARACTER STRING
BMPString
ISO646String
TeletexString

Tag

dec/hex
[07/07]

[08/08]
[11/0B]

[35/ *]
[36/ *]

[17/11]
[17/11]

[23/17]
[24/18]

[19/13]
[20/14]
[21/15]
[25/19]
[27/1B]
[28/1C]
[29/1D]
[30/1E]
[26/1A]
[20/14]

 

Information Objects

Use of upper/lower case after ‘&’ is semantically significant.

MY-SIMPLE-CLASS ::= TYPE-IDENTIFIER

MY-CLASS ::= CLASS {
  &id OBJECT IDENTIFIER UNIQUE,
  &simple-value ENUMERATED {high, low} DEFAULT low,
  &Set-of-values INTEGER OPTIONAL,
  &Any-type,
  &an-inform-object SOME-CLASS,
  &A-set-of-objects SOME-OTHER-CLASS
} WITH SYNTAX
    {   KEY           &id
      [ URGENCY &simple-value ] -- Optional
      [ VALUE-RANGE &Set-of-values ]
      PARAMETERS &Any-type
      SYNTAX  &an-inform-object
      MATCHING-RULES  &A-set-of-objects
   }

my-object MY-CLASS ::= {
    KEY { ....... }
    URGENCY high
    VALUE-RANGE { 1..10 | 20..30 }
    PARAMETERS My-type
    SYNTAX defined-syntax
    MATCHING-RULES { at-start | at-end | exact }
}

My-object-set MY-CLASS ::= {
                object1 | object2 | object3,
                ...,
                version2-object
}

Message ::= SEQUENCE {
    -- Has to be an OBJECT IDENTIFIER (KEY) from the set:
    key MY-CLASS.&id ({My-object-set}),
    -- Has to be the PARAMETERS for the object with KEY:
    parms MY-CLASS.&Any-type ( {My-object-set} {@key} )
}

Variable type value fields and value set fields are out of the scope of this reference card

 

VALUES

Values are usually specified in ASN.1 modules only for indicating defaults, or ranges for constraining items (such as the maximum length of a name).

defaultOn BOOLEAN ::= TRUE
maxAge INTEGER ::= 120
bitmask BIT STRING ::= ‘7FFF’H
defaultBytes OCTET STRING ::= ‘010F’H
placeholder NULL ::= NULL
defaultID OBJECT IDENTIFIER ::= {joint-iso-itu-t country(16) us(840)}
defaultPrice REAL ::= 9.99

Item          ::= SEQUENCE {
   id               CHOICE { -- id alternatives - code, url or color
                      code   INTEGER (0..MAX),
                      url    VisibleString,
                      color  ENUMERATED { black, blue, ... ,-- extended
                                          green, red}
   } DEFAULT code:9999,
   quantity         INTEGER {single(1), dozen(12), crate(36)},
   options          BIT STRING DEFAULT '101100011'B,
   unitPrice        REAL ( 1.00 .. 9999.00 ),
                    ... , -- extension allowed below this line
   [[ isTaxable BOOLEAN DEFAULT FALSE ]], -- added to Item in v.2
   [[ voltage INTEGER (110 | 220) OPTIONAL ]] -- added in v.3
}
defaultItem Item ::= { -- This is a value for the type above
   id code : 1,
   quantity single,
   options '0'B,
   unitPrice 1.99
}

ListOfNumbers ::= SEQUENCE OF INTEGER
firstPrimeNumbers ListOfNumbers ::= {1, 2, 3, 5, 7, 11, 13, 17}

name1 UTF8String ::= “Joe” -- can also hold international characters
phone NumericString ::= “8885551212”
text IA5String ::= “Arbitrary text - with punctuation, no problem.”
name2 VisibleString ::= “Joe” -- US ASCII without control characters

myDay DATE ::= “2012-01-31”
noon TIME-OF-DAY ::= “12:00:00”
noonMyDay DATE-TIME ::= “2012-01-31T12:00:00”
lunchtime DURATION ::= “PT1H” -- one hour for lunch

Here is a common use for value notation for limiting a string size, especially if the same value will be used in multiple places:

upperSize INTEGER ::= 64
VisibleString (SIZE (0..upperSize) )
ItemList ::= SEQUENCE (SIZE(0..upperSize)) OF Item

 

PARAMETERIZATION

All assignments defining reference names (type, value, class definitions, object definitions, object set) can be given a dummy parameter list. Here we have two dummy parameters - normal-priority and Parameter.

Invoke-message {INTEGER:normal-priority, Parameter} ::=
SEQUENCE {
component1 INTEGER DEFAULT normal-priority,
component2 Parameter }

Now we define our messages as a choice of two possibilities that differ only in the default priority and the Type that is to be used:

Messages ::= CHOICE {
   first Invoke-message { low-priority, Type1 },
   second Invoke-message { high-priority, Type2 },
   ... }

Messages ::= CHOICE { -- This is what the above expands to
   first SEQUENCE {
     component1 INTEGER DEFAULT low-priority,
     component2 Type1 },
   second SEQUENCE {
     component1 INTEGER DEFAULT high-priority,
     component2 Type2 },
   ... }

 

ENCODINGS

Bit-wide

PER: A compact binary encoding transferring the minimum information needed to identify a value.

Byte-wide

OER: A byte-aligned encoding designed for fast encoding/decoding

BER: A type-length-value (TLV) style of encoding

DER: An encoding with only one way to encode a given value, used in security work.

CER: Another security-related encoding, rarely used.

XML

XER: Encoding ASN.1 values as XML syntax.

There are also Encoding Instructions that can vary XERand other encodings, for example, to determine which components of a sequence are to be encoded as XML attributes.

ECN

An encoding control notation (ECN) is available to completely determine the encoding of ASN.1 values.