Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

ASN1 Base

All the ASN1 fundamental data types inherit from the asn_base_t class. This class is a interface class that provides some basic functionality for ASN1 objects.

Any ASN1 object that is derived from asn_base_t must provide clone(), create(), encode() and decode() methods.

Tag/Length/Value

The ASN1 encoding scheme requires tag identification, length of the data and the actual data to be sent. For instance, an integer that has a value of one would encode as follows:

[ Integer tag ] [ 1 ] [ 1 ]

When ASN1 types are encoded into a container, the length of the container is the sum of the objects contained within, including their tags, length field and data length.

[ Container tag ] [ 10 ]
  [ Integer tag ] [ 1 ] [ 1 ]
  [ String tag ]  [ 5 ] [ 'text.' ]

Some tags require a zero termination to identify their end. Zero termination is known as the indefinate form of encoding. For example, an indefinate string would be encoded as:

[ String tag ]  [ 0 ] [ 'text.' 0 ]

Memory

The ASN1 library relies heavily on the Boost Smart Pointer Library for pointer storage. The create() and clone() methods return a asn_base_ptr object. This is declared as a typedef:

typedef shared_ptr<asn_base_t> asn_base_ptr;

The asn_base_t class is declared using the Boost shared_ptr template enable_shared_from_this.

Validity

Sometimes, data that is stored in an ASN1 type object does not meet the requirements of valid data. For instance, the time objects require a valid date. It is suggested to use the isValid() method prior to encoding data. When data is stored in a ASN1 container, the container inherits it's validity from all the children present. This makes it easier to know if you have a valid packet of data prior to encoding and transmitting it.

Encoding

Every ASN1 object must provide it's own encode() and decode() methods. These methods are used by the asn_visitor_t objects that execute the encoding and decoding of ASN1 data packets. For more information on this topic, see the Data Encoding section.

Copyright © 2007 Andreas Haberstroh

PrevUpHomeNext