Specific ASN.1 Type to Value Mappings

This section defines the type-to-value mapping for each of the specific ASN.1 types. By default, these mappings are not in the form defined in the ASN.1 XML Encoding Rules (XER) standard (ITU-T X.693).

When a schema is provided using the -schema option, the output may be adjusted to conform to XER if desired by using the -xer option. XER is more verbose and less validation-friendly than our native XML export. It is provided for those occasions when strict conformance is required. Differences between the two formats are provided along with the schemaless mappings below.

BOOLEAN. An ASN.1 boolean value is transformed into the keyword 'true' or 'false'. If BER/DER/CER data is being decoded without a schema and the universal tag for this type is parsed, a <BOOLEAN> tag is added.

b BOOLEAN ::= TRUE  
Schemaless
<BOOLEAN>TRUE</BOOLEAN>
XML Mode
<b>true</b>
XER Mode
<b>
   <TRUE/>
</b>

INTEGER. An ASN.1 integer value is transformed into numeric text. The one exception to this rule is if named number identifiers are specified for the integer type. In this case, if the number matches one of the declared identifiers, the identifier text is used.

If BER/DER/CER data is being decoded without a schema and the universal tag for this type is parsed, an <INTEGER> tag is added.

i INTEGER ::= 35  
Schemaless
<INTEGER>TRUE</INTEGER>
With schema
<i>35</i>

ENUMERATED. An ASN.1 enumerated value is transformed into the enumerated identifier text value. If BER/DER/CER data is being decoded without a schema and the universal tag for this type is parsed, an <ENUMERATED> tag is added.

colors ENUMERATED {red, green, blue} ::= green  
Schemaless
<ENUMERATED>1</ENUMERATED>
XML Mode
<e>green</e>
XER Mode
<e>
   <green/>
</e>

BIT STRING. An ASN.1 bit string value is transformed into one of three forms:

  1. Binary Text (0's and 1's)

  2. Hexadecimal text

  3. Named bit identifiers

Binary text is the default output format. This is used if the bit string type contains no named bit identifiers and if specification of hexadecimal output was not specified on the asn2txt command-line.

Hexadecimal text is displayed when the -bitsfmt hex command-line option is used. Any unused bits in the last octet are set to zero. Note that the other bits are displayed in most-significant bit order as they appear in the string in the last byte (i.e., they are not right shifted). For example, if the last byte contains a bit string value of 1010xxxx (where x denotes an unused bit), the string is displayed as A0 in the XML output, not 0A.

Named bit identifiers are used in the case of a bit string declared with identifiers. In this case, the XML content is a space-separated list of identifier values corresponding to the bits that are set. It is assumed that bits in the string all have corresponding identifier values.

If BER/DER/CER data is being decoded without a schema and the universal tag for this type is parsed, a <BIT_STRING> tag is added.

bs BIT STRING { zero(0), a(1), b(3), c(5) } ::= '100100'B  
Schemaless
<BIT_STRING>100100</BIT_STRING>
With schema
<bs>100100</b>

OCTET STRING. An ASN.1 octet string value is transformed into one of two forms:

  1. Hexadecimal text

  2. ASCII character text

Hexadecimal text is the default display type. ASCII text will be used for the content when the -ascii command-line option is used and the field contains are printable ASCII characters.

A special case of OCTET STRING handling is for declared binary-coded decimal (BCD) data types. This is discussed in a later section.

If BER/DER/CER data is being decoded without a schema and the universal tag for this type is parsed, a <OCTET_STRING> tag is added.

os OCTET STRING ::= '3031'H  
Schemaless
<OCTET_STRING>3031</OCTET_STRING>
With schema
<os>3031</os>
With -ascii
<os>01</os>

NULL. An ASN.1 null value is displayed as an empty XML element. If BER/DER/CER data is being decoded without a schema and the universal tag for this type is parsed, a <NULL> tag is added.

n NULL ::= NULL  
Schemaless
<NULL/>
XML Mode
<n/>
XER Mode
<n>
   <NULL/>
</n>

OBJECT IDENTIFIER and RELATIVE OID. An ASN.1 object identifier value is mapped into space-separated list of identifiers in numeric and/or named-number format. The identifiers are enclosed in curly braces ({}). Numeric identifiers are simply numbers. The named-number format is a textual identifier followed by the corresponding numeric identifier in parentheses. It is used in cases where the identifier can be determined from the schema or is a well known identifier as specified in the ASN.1 standard.

If BER/DER/CER data is being decoded without a schema and the universal tag for this type is parsed, a <OBJECT_IDENTIFIER> tag is added.

oid OBJECT IDENTIFIER ::= { 1 2 840 113549 1 1 2 }  
Schemaless
<OBJECTIDENTIFIER>{ 1 2 840 113549
   1 1 2 }</OBJECTIDENTIFIER>
With schema
<oid>{ 1 2 840 113549 1 1 2 }</oid>

The mapping for RELATIVE OID is the same as that for OBJECT IDENTIFIER.

Character String. An ASN.1 value of any of the known character string types is transformed into the character string text in whatever the default encoding for that type is. For example, an IA5String would contain an ASCII text value whereas a BMPString would contain a Unicode value.

If BER/DER/CER data is being decoded without a schema and the universal tag for this type is parsed, a tag is added which is the name of the character string type as defined in the ASN.1 standard in angle brackets. For example, the default tag for a UTF8String type would be <UTF8String>.

str UTF8String ::= "testing"  
Schemaless <UTF8String>testing</UTF8String>
With schema <str>testing</str>

Binary-coded Decimal String. Binary-Coded Decimal (BCD) strings and Telephony Binary-Coded Decimal (TBCD) strings are not part of the ASN.1 standard, but their use is prevalent in many telephony-related ASN.1 specifications.

Conversion of these types into standard numeric text strings is supported.

In general, BCD strings pack two numeric digits into a single byte value by using a four-bit nibble to hold each digit. By convention, the digits are reversed in TBCD strings, but there are no official standards for this encoding.

The -bcdhandling command-line option can be used to force a certain type of conversion if an encoding does not follow the usual conventions. The default handling is to reverse digits in string determined to be TBCD strings and not reverse digits in BCD strings. The bcd option is used to for no reversal of digits in all of these types of strings. The tbcd option instructs ASN2TXT to reverse the digits for all BCD strings.

If no processing is desired, -bcdhandling none can be used to instruct ASN2TXT not to process these strings.

REAL. An ASN.1 real value is transformed into numeric text in exponential number format. If BER/DER/CER data is being decoded without a schema and the universal tag for this type is parsed, a <REAL> tag is added.

r REAL ::= 2.99  
Schemaless
<REAL>2.99</REAL
With schema
<r>2.99</r>

SEQUENCE and SET. An ASN.1 sequence value is transformed into an XML value containing an element wrapper with each of the XML element encoded values inside.

Name ::= SEQUENCE {
 first  UTF8String,
 middle UTF8String OPTIONAL,
 last   UTF8String
}
name Name ::= {
 first "Joe",
 last  "Jones"
}
Schemaless
<SEQUENCE>
 <CONTEXT_0>
  <UTF8String>Joe</UTF8String>
  </CONTEXT_0>
 <CONTEXT_2>
   <UTF8String>Jones</UTF8String>
 </CONTEXT_2>
</SEQUENCE>
With schema
<name>
   <first>Joe</first>
   <last>Jones</last>
</name>
With -emptyOptionals
<name>
   <first>Joe</first>
   <middle/>
   <last>Jones</last>
</name>

When a SET is used instead, the outer SEQUENCE tag is replaced with SET. The mappings are otherwise identical.

SEQUENCE OF / SET OF. The representation of a repeating value in XML varies depending on the type of the element value.

If the value being translated is a sequence of an atomic primitive type, the XML content is a space- separated list of values. The definition of "atomic primitive type" is any primitive type whose value may not contain embedded whitespace. This includes BOOLEAN, INTEGER, ENUMERATED, REAL, BIT STRING, and OCTET STRING values.

If the value being translated is a constructed type or if it may contain whitespace, the value is wrapped in a tag which is either the name of the encapsulating type (defined or built-in) or the SEQUENCE OF element name if this form of the type was used.

If BER/DER/CER data is being decoded without a schema and the universal tag for this type is parsed, a <SEQUENCE> or <SET> tag is added. That is because the tag value (hex 30 or 31) is the same for SEQUENCE OF or SET OF as it is for SEQUENCE or SET.

soi SEQUENCE OF INTEGER ::= {1, 2, 3}
 
Schemaless
<SEQUENCE>
 <INTEGER>1</INTEGER>
 <INTEGER>2</INTEGER>
 <INTEGER>3</INTEGER>
</SEQUENCE>
With schema
<soi>
 <INTEGER>1</INTEGER>
 <INTEGER>2</INTEGER>
 <INTEGER>3</INTEGER>
</soi>

sos SEQUENCE OF UTF8String ::= {
  "test 1",
  "test 2"
}
 
Schemaless
<SEQUENCE>
 <UTF8STRING>test 1</UTF8STRING>
 <UTFSTRING>test 2</UTF8STRING>
</SEQUENCE>
With schema
<sos>
 <UTF8String>test 1</UTF8String>
 <UTF8String>test 2</UTF8String>
</sos>

Name ::= SEQUENCE {
 first  UTF8String,
 middle UTF8String OPTIONAL,
 last   UTF8String
}
son SEQUENCE OF Name ::= {
  { first 'Joe',
    last  'Jones' },
  { first 'John',
    middle 'P',
    last 'Smith' }
}
Schemaless
<SEQUENCE>
 <SEQUENCE>
  <UTF8STRING>Joe</UTF8STRING>
  <UTF8STRING>Jones</UTF8STRING>
 </SEQUENCE>
 <SEQUENCE>
  <UTF8STRING>John</UTF8STRING>
  <UTF8STRING>P</UTF8STRING>
  <UTF8STRING>Smith</UTF8STRING>
 </SEQUENCE>
</SEQUENCE>
With schema (this example shows the result with -emptyOptionals selected; the empty <middle/> element would be omitted if that option were not used)
<son>
 <Name>
  <first>Joe</first>
  <middle/>
  <last>Jones</last>
 </Name>
 <Name>
  <first>John</first>
  <middle>P</middle>
  <last>Smith</last>
 </Name>
</son>

CHOICE. The mapping of an ASN.1 CHOICE value is the alternative element tag followed by the value translated to XML format.

C ::= CHOICE {
   a INTEGER,
   b OCTET STRING,
   c UTF8String
}
c C ::= { c : "test value" }
Schemaless
<UTF8STRING>test value</UTF8STRING>
With schema
<C>
   <c>test value</c>
</C>

Open Type. The mapping of an ASN.1 open type value depends on whether the actual type used to represent the value can be determined. ASN2XML attempts to determine the actual type using the following methods (in this order):

  1. Table constraints

  2. Tag lookup in all defined schema types (BER/DER/CER only)

  3. Universal tag lookup (BER/DER/CER only)

If the type can be determined, an XML element tag containing the type name is first added followed by the translated content of the value.

If the type cannot be determined, the open type content is translated into hexadecimal text from of the encoded value. This will also be done if the -noopentype command-line switch is used.

As an example, consider the AlgorithmIdentifier type used in the AuthenticationFramework and other related security specifications:

AlgorithmIdentifier ::= SEQUENCE {
  algorithm  ALGORITHM.&id({SupportedAlgorithms}),
  parameters ALGORITHM.&Type({SupportedAlgorithms}{@algorithm}) OPTIONAL
}

In this case, the parameters element references an open type that is tied to a type value based on the value of the algorithm key. Without getting into the details of the use of the accompanying information object sets, it is known that for an algorithm value of object identifier { 1 2 840 113549 1 1 2 }, the type of the parameters field is NULL (i.e. there are no associated parameters). The XML translation in this case will be the following:

<algorithm>{ 1 2 840 113549 1 1 2 }</algorithm>
<parameters>
   <NULL/>
</parameters>