CSN.1 to ASN.1 Example

In this section, a sample CSN.1 file is presented, along with the corresponding ASN.1. There is little to no commentary here, as the chapter that defines the mappings really is the commentary. The majority of the patterns that may be recognized are illustrated in this sample.

Example 19.5. CSN.1 Example

ASN1MODULE : UserGuide;

-- This is a definition where the right hand side is mapped to a component and
-- the whole is therefore mapped into a SEQUENCE
<SingleComponent> ::= 0 | 1 <fields: <field1: bit(4)> <field2: bit(3)>>;

-- This example illustrates some of the effects of naming
<Naming> ::=
   <ALL CAPS 1: bit(1)>  --becomes all-caps-1
   <PART Caps: bit(1)>   --becomes part-Caps
   <CamelCase: bit(1)>   --becomes camelCase
;

--Illustrate various patterns of alternation
<Alternations> ::=
   <l bit or h bit?: L | H>
   <particular general:
      010 <Naming> |
      {<pg determinant: bit(3)> exclude 010} <something else: bit(4)>
   >
   <stereo choice 1 :
      0 <first: bit(1)> | 1 <second: bit(2)> >
   <stereo choice 2 :
      00 | 01 <first: bit(1)> | 11 <second: bit(2)> | <third: 10> >
   <optional with presence bit: 0 | 1 <maybe : bit(4)>>
   <optional with presence bit and container determined: null | 0 | 1 <possibly : bit(3)>>
   <optional container determined: null | <questionable: bit(2)>>
;

<padding> ::= {<bit> send 0} **;

<Length Constrained Content> ::=
   <length : bit(7)>
   {
      { <willy nilly: bit(4)> 
                     { 0 | 1 bit(3) } 
                     <padding> 
      } & octet(val(length))
   }
;

<Concat> ::=
{
   <e1: bit(1)>
   {
      --This nesting will get removed
      <e2: bit(2)>
      <e3: bit(3)>
   }
   <e4: bit(4)>
   <a pad bit: <bit> send 0>
   <some literal bits: 0101001>
   <single bit: bit>
   <single octet: octet>
   <ref to a name: Naming>
   { 1 <two bit value using more/done bit: bit(2)> }** 0
   <named list: { 1 <two bit value using more/done bit: bit(2)> }** 0 >
   <list of 10: <value: bit(4)>(10)>
   <list ending with container: bit(3)>**
};

--Truncated concatenation.
<Truncated Concat> ::=
{
   <e1: bit(1)>
   {
      --This nesting will NOT get removed
      <e2: bit(2)>
      <e3: bit(3)>
   }
   <e4: bit(4)>
}//
;

<Things With Exponents> ::=
   <a 23-bit int: bit(23)>
   <a fixed length bit string: bit(45)>
   <a var length bit string: bit(val(a 23-bit int))>
   <a fixed length octet str: octet(4)>
   <a var len octet str: octet(val(a 23-bit int))>
   <repeating optional component: {0 | 1 <opt comp: bit(4)>}(5)>
   <five pad bits: <bit> send 0>(5)
   <count bit encoding: 0** 1>
   <fixed num of type: Naming(5)>
   <var num of type: Naming(val(a 23-bit int))>
;            
        

The resulting ASN.1 follows. Our tool generates tags in the ASN.1; these have been removed to improve readability.

Example 19.6. The resulting ASN.1

UserGuide DEFINITIONS AUTOMATIC TAGS ::= BEGIN

-- Productions

LHType ::= ENUMERATED { lbit(0), hbit(1) }

Naming ::= SEQUENCE {
   all-caps-1  INTEGER (0..1),
   part-Caps  INTEGER (0..1),
   camelCase  INTEGER (0..1)
}

Alternations ::= SEQUENCE {
   l-bit-or-h-bit  LHType,
   pg-determinant  INTEGER (0..7),
   particular-general  CHOICE {
      naming  Naming,
      something-else  INTEGER (0..15)
   },
   stereo-choice-1  CHOICE {
      first  INTEGER (0..1),
      second  INTEGER (0..3)
   },
   stereo-choice-2  CHOICE {
      choice-1  NULL,
      first  INTEGER (0..1),
      second  INTEGER (0..3),
      third  NULL
   },
   maybe  INTEGER (0..15) OPTIONAL,
   possibly  INTEGER (0..7) OPTIONAL,
   questionable  INTEGER (0..3) OPTIONAL
}

Concat ::= SEQUENCE {
   e1  INTEGER (0..1),
   e2  INTEGER (0..3),
   e3  INTEGER (0..7),
   e4  INTEGER (0..15),
   a-pad-bit  INTEGER (0..1) DEFAULT 0,
   some-literal-bits  INTEGER (41) DEFAULT 41,
   single-bit  INTEGER (0..1),
   single-octet  INTEGER (0..255),
   ref-to-a-name  Naming,
   two-bit-value-using-more-done-bit-list  SEQUENCE OF INTEGER (0..3),
   named-list  SEQUENCE OF INTEGER (0..3),
   list-of-10  SEQUENCE (SIZE (10)) OF INTEGER (0..15),
   list-ending-with-container  SEQUENCE OF INTEGER (0..7)
}

Length-Constrained-Content ::= SEQUENCE {
   length  INTEGER (0..127),
   willy-nilly  INTEGER (0..15),
   component-3  INTEGER (0..7) OPTIONAL
}

SingleComponent ::= SEQUENCE {
   fields  SEQUENCE {
      field1  INTEGER (0..15),
      field2  INTEGER (0..7)
   } OPTIONAL
}

Things-With-Exponents ::= SEQUENCE {
   a-23-bit-int  INTEGER (0..8388607),
   a-fixed-length-bit-string  BIT STRING  (SIZE (45)),
   a-var-length-bit-string  BIT STRING  (SIZE (0..8388607)),
   a-fixed-length-octet-str  OCTET STRING (SIZE (4)),
   a-var-len-octet-str  OCTET STRING (SIZE (0..8388607)),
   repeating-optional-component  SEQUENCE (SIZE (5)) OF SEQUENCE {
      opt-comp  INTEGER (0..15) OPTIONAL
   },
   five-pad-bits  INTEGER (0..31) DEFAULT 0,
   count-bit-encoding  INTEGER (0..255),
   fixed-num-of-type  SEQUENCE (SIZE (5)) OF Naming,
   var-num-of-type  SEQUENCE (SIZE (0..8388607)) OF Naming
}

Truncated-Concat ::= SEQUENCE {
   e1  INTEGER (0..1) OPTIONAL,
   component-2  SEQUENCE {
      e2  INTEGER (0..3),
      e3  INTEGER (0..7)
   } OPTIONAL,
   e4  INTEGER (0..15) OPTIONAL
}

END