ASN.1
Previous: Simple Types Up: Built-in Types Next: Tagged Types


Structured Types

ASN.1's built-in structured types are shown in the following Table. The universal class number (tag) and a typical use of each type are also included.

Structured Types Tag Typical Use
SEQUENCE 16 Models an ordered collection of variables of different type
SEQUENCE OF 16 Models an ordered collection of variables of the same type
SET 17 Model an unordered collection of variables of different types
SET OF 17 Model an unordered collection of variables of the same type
CHOICE * Specify a collection of distinct types from which to choose one type
SELECTION * Select a component type from a specified CHOICE type
ANY * Enable an application to specify the type
Note: ANY is a deprecated ASN.1 Structured Type. It has been replaced with X.680 Open Type.

Table: Structured types in ASN.1, their universal tags, and uses. * indicates more than one tag. For a full list of Universal Tags, see the Universal Tags page.

Type SEQUENCE is an ordered list of zero or more component types. The type notation requires braces around the list and permits a local identifier preceding the list to act as the name of the sequence type. The identifier increases readability. There are two ways to specify that a component type is optional in the ordered list: using OPTIONAL after the component type and using DEFAULT followed by a value after the component type. When DEFAULT is used, the specified value is assumed whenever the type is absent from the list. Any of the component types can be an embedded sequence, in which case COMPOSED OF precedes the embedded sequence. The value notation for each sequence type is the list of component values within braces. For readability, it is recommended that the component identifier precedes each ordered list of values. For example,

      {
      airline   "American",
      flight    "1106",
      seats     { 320, 107, 213 },
      airport   { origin  "BWI", destination  "LAX" },
      crewsize  10
      }
or
     {
      "American", "1106", { 320, 107, 213 }, { "BWI", "LAX" }, 10
     }

represent the same instance of the sequence type

  AirlineFlight  ::=  SEQUENCE
     {
      airline   IA5String,
      flight    NumericString,
      seats     SEQUENCE
                    {
                     maximum   INTEGER,
                     occupied  INTEGER,
                     vacant    INTEGER
                    },
      airport   SEQUENCE
                    {
                     origin             IA5String,
                     stop1       [0]    IA5String  OPTIONAL,
                     stop2       [1]    IA5String  OPTIONAL,
                     destination        IA5String
                    },
       crewsize ENUMERATED
                    {
                      six    (6),
                      eight  (8),
                      ten    (10)
                    },
       cancel   BOOLEAN    DEFAULT FALSE
      }.

This instance of AirlineFlight indicates that American Airlines flight 1106 flies non-stop from Baltimore-Washington Airport to Los Angeles. The airplane requires a crew of 10 people, has 320 seats, of which 107 are filled and 213 are empty. The flight is not canceled. Two components, Stop1 and Stop2 of the sequence type airport are tagged with the context-specific tags [0] and [1] (See Tagged Types Section) to avoid ambiguity due to consecutive optional components not having distinct types. Without the tags, the definition of airport would be invalid in ASN.1.

Type SEQUENCE OF is similar to SEQUENCE, except that all values in the ordered list must be of the same type. For example, the seats type in the above example could be SEQUENCE OF INTEGER instead of SEQUENCE.

Type SET takes values that are unordered lists of component types. The type and value notations for SET are similar to SEQUENCE, except that the type of each component must be distinct from all others and the values can be in any order. For example,

  {"Maggie", 4, TRUE}   {TRUE, "Maggie", 4}   {4, TRUE,"Maggie"}

are three representations of the same instance of

  Person  ::=  SET
      {
       name      IA5String,
       age       INTEGER,
       female    BOOLEAN
      }.

In the type SEQUENCE example above, using SET instead of SEQUENCE for the seats type would be invalid in ASN.1 because at least two of the components (all of them in this case) are of the same type. In particular, if the type were SET, then 180, 0, 180 and 180, 180, 0 would be the same value and the receiving system could not determine whether all seats were filled or empty.

Type SET OF takes values that are unordered lists of a single type. The SEQUENCE type example above would be valid if the seats type were SET OF INTEGER instead of SEQUENCE, but would be ambiguous in some instances, such as in the example of the preceding paragraph.

Type CHOICE takes one value from a specified list of distinct types. The alternative types are contained in braces and may be preceded by local identifiers. The value notation is that for the type chosen. For example, each of the three values,

 (1) nothing  TRUE,  (2) car  "Lincoln",  (3) cash  25000

is a valid instance of

     Prize  ::=  CHOICE
       {
        car        IA5String,
        cash       INTEGER,
        nothing    BOOLEAN
       }.

Type SELECTION enables the user to choose a component type from a specified CHOICE type. The less than symbol ``<" must precede the name of the CHOICE type. For example, the component cash of CHOICE type Prize can appear in a specified SEQUENCE type

     Winner  ::=  SEQUENCE
       {
        lastName    VisibleString,
        ssn         VisibleString,
        cash   <    Prize
       }

with value notation

       {
        lastName    `AUSTING',
        ssn         `222334444',
        cash        5000
       }

Type ANY, without further specification, is incomplete. It must be supplemented by any valid ASN.1 type defined in another module. ANY can be used, for example, in a user data field definition within a PDU. The application then specifies the type. The value notation for the type notation ANY is the specified type followed by its value. For example,

    {
      author      "Shakespeare",
      reference   IA5String  "ISBN0669123757"
    }

and

    {
      author      "Shakespeare",
      reference   INTEGER    1988
    }

are two possible values of

  TextBook  ::=  SEQUENCE
    {
      author      IA5String,
      reference   ANY
    }

The ASN.1 standard allows an alternative, ANY DEFINED BY, within type SEQUENCE or SET only. The type notation is ANY DEFINED BY followed by an identifier, a non-optional component of the SEQUENCE whose type is either INTEGER or OBJECT IDENTIFIER. The identifier acts as a pointer to where the type is defined. For example, the definition

  TextBook  =  SEQUENCE
    {
      author          IA5String,
      CitationType    INTEGER,
      reference       ANY DEFINED BY CitationType
    },

requires a list of CitationTypes defined elsewhere that specifies the ASN.1 type for each permitted value of INTEGER. In particular, if the list defined 0, 1, and 2 as IA5String, INTEGER, and PrintableString, respectively, then textbook could have values such as:

  {
   author        "Shakespeare",
   CitationType  0,
   reference  IA5String  "ISBN0669123757"
  }
  or
  {
   author        "Shakespeare",
   CitationType  1,
   reference  INTEGER  1988
  }
  or
  {
   author        "Shakespeare",
   CitationType  2,
   reference  PrintableString  "D.C. Heath"
  }

Previous: Simple Types Up: Built-in Types Next: Tagged Types


This site was developed from:
Computer Networks and Open Systems
An Application Development Perspective

by
Lillian N. Cassel
Richard H. Austing

Jones & Bartlett Publisher
ISBN 0-7637-1122-5

This site is hosted by:


Real World ASN.1 and XML Solutions