previous | start

Subranges and "Derived Types" in ASN.1

In "pure" ASN.1, there are no constraints on the range of values that a variable can take. This is in contrast to "real world" languages such as Java and C where data items are usually associated with "reserved storage" -- eg, defining an integer typically reserves 4 bytes (32 bits) of memory in the program's data area.
 
Most ASN.1-based applications (eg SNMP) use derived types, which are specified using the sub-range (or sub-type) capabilities of the language[3]. These types usually match up with the storage which the application will reserve for them. Some examples include:
 
Month ::= INTEGER (1..12) 
Day ::= INTEGER (1..31) 
Daily-temperatures ::= SEQUENCE SIZE (31) OF INTEGER 
Name ::= PrintableString (SIZE (1..20 )) 

Digression on ASN.1 Syntax Conventions

In writing ASN.1 specifications, the case of the characters used conventionally indicates to a human reader the part of the ASN.1 grammar in use. Thus:
 

 
Note that in these notes, an attempt will also be made to present all ASN.1 (and other) syntactic elements in the fixed-width courier typeface. Occasional lapses from this convention may have to be forgiven by the reader... Examples:
MyType ::= TYPE
nameOfValue MyType ::= VALUE
Note also that, where appropriate, we adopt the OSI convention of referring to "octets", instead of "bytes", even though the terms have almost universally identical meaning.
 
[3] These are usually given APPLICATION-specific tags, as noted earlier, although some are sufficiently important to be defined in the standard.
[4] Reminding us of the quote from Though The Looking Glass by Lewis Carroll: "When I use a word," Humpty Dumpty said in rather a scornful tone, "it means just what I choose it to mean -- neither more nor less."...
Lecture 21: Network Management #1 Copyright © 2005 P.Scott, La Trobe University Bendigo.
The tutorial for this lecture is Tutorial #21.
La Trobe Uni Logo [Previous Lecture] [Lecture Index] [Next Lecture]
Copyright © 2005 by Philip Scott, La Trobe University.
Valid HTML 3.2!

previous | start