Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

ASN1 Notation

Abstract Syntax Notation One (ASN1) was designed for the express purposes of defining data interchange protocols between applications, independent of platform. The syntax defines a number of primitive data types that most languages support; integrals, strings, structures, lists. Reading the notation from a C++ perspective requires you to think backwards, variables are listed first and type is second.

RecordNumber INTEGER

The syntax also contains expressions that act as modifiers to data types. Any data type can be defined OPTIONAL. I think the meaning of that is pretty straight forward. However, some data types can have constrained ranges for data to be considered valid. If we want to define an INTEGER that represents seconds, and it should only contain numbers 0 thru 59, we can notate it ASN1 as follows:

Seconds INTEGER (0-59)

Protocols send their information in packets which ASN1 defines as a Production Data Unit or a PDU. PDU's are made up of a sequence of data, and therefore use the ASN1 type SEQUENCE to define the start of a PDU.

Each PDU starts with a name for the SEQUENCE, followed by an assignment operator, and a list of items enclosed by braces. For example, an application wants to send a message that contains a username and password, this could notated in ASN1 as follows:

Authenticate := SEQUENCE {
  MessageID INTEGER,
  UserName IA5STRING,
  Password OCTET STRING
  }

Copyright © 2007 Andreas Haberstroh

PrevUpHomeNext