ASN.1 default value handling is partially supported

ASN.1 supports the definition of default values within the ASN.1 structure definition document. If an ASN.1 field with a default value does not occur in the encoded data, then the ASN1Parse operator uses the provided default value.

ASN1Parse supports only directly provided single default values in double quotes as shown in the following table.

Hint: The ASCII (American Standard Code for Information Interchange) is a character encoding scheme.

ASN.1 Type

Supported DEFAULT Format Examples

BIT STRING

any combination of 0 and 1 characters


field [0] BIT STRING DEFAULT ""
field [0] BIT STRING DEFAULT {}
field [0] BIT STRING DEFAULT "0110" -- characters ‘0’ and ‘1’ only

BMPString

any UTF-8 string


field [0] BMPString DEFAULT "any UTF-8 text"

BOOLEAN

any of the typical boolean values (0, 1, true, false, TRUE, FALSE)


field [0] BOOLEAN DEFAULT "true"
field [0] BOOLEAN DEFAULT "TRUE"
field [0] BOOLEAN DEFAULT "1"
field [0] BOOLEAN DEFAULT "false"
field [0] BOOLEAN DEFAULT "FALSE"
field [0] BOOLEAN DEFAULT "0"

ENUMERATED

either the name or the value of the enumeration id


EnumerationType ::= ENUMERATED { black (0), white (1) }
field [0] EnumerationType DEFAULT "1" -- or any other integer
field [0] EnumerationType DEFAULT "white"

GeneralizedTime

any format specified in ITU X.680 and ISO 8601, i.e. local time, UTC time or time with timezone, e.g.


field [0] GeneralizedTime DEFAULT "20001231235959.999"
field [0] GeneralizedTime DEFAULT "20001231205959.999Z"
field [0] GeneralizedTime DEFAULT "20001231235959.999+0300"

GeneralString

any hex dump is allowed


field [0] GeneralString DEFAULT "313233"

GraphicString

any hex dump is allowed


field [0] GraphicString DEFAULT "313233"

IA5String

any 7-bit ASCII character string


field [0] IA5String DEFAULT "Hello"

INTEGER

any integer


field [0] INTEGER DEFAULT "35"

ISO646String

any 7-bit ASCII character (between 0x20 and 0x7E) string


field [0] ISO646String DEFAULT "Hello"

NULL

default makes no sense, but is still supported


field [0] NULL DEFAULT ""

NumericString

any numeric string (digits only)


field [0] NumericString DEFAULT "1234"

ObjectDesrciptor

any UTF-8 string


field [0] ObjectDescriptor DEFAULT "Hello World."

OBJECT IDENTIFIER

any dot-separated list of unsigned integers


field [0] OBJECT IDENTIFIER DEFAULT "1.2.4.8.16.0"

OCTET STRING

any hex dump is allowed


field [0] OCTET STRING DEFAULT "313233"

PrintableString

any ASCII string with Latin letters, digits and some few other characters, as specified in ITU X.680.


field [0] PrintableString DEFAULT "Hello World."

REAL

any real value with/without exponent or special meaning


field [0] REAL DEFAULT "3.14159"
field [0] REAL DEFAULT "314159e-5"
field [0] REAL DEFAULT "PLUS-INFINITY"
field [0] REAL DEFAULT "MINUS-INFINITY"
field [0] REAL DEFAULT "NOT-A-NUMBER"

RELATIVE-OID

any dot-separated list of unsigned integers


field [0] RELATIVE-OID DEFAULT "1.2.4.8.16.0"

T61String

any hex dump is allowed


field [0] T61String DEFAULT "313233"

TeletexString

any hex dump is allowed


field [0] TeletexString DEFAULT "313233"

UniversalString

any UTF-8 string


field [0] UniversalString DEFAULT "Hello World."

UTCTime

any format specified in ITU X.680, i.e. local time, UTC time or time with timezone, e.g.


field [0] UTCTime DEFAULT "001231235959"
field [0] UTCTime DEFAULT "001231205959Z"
field [0] UTCTime DEFAULT "001231235959+0300"

UTF8String

any UTF-8 string


field [0] UTF8String DEFAULT "Hello World."

VideotexString

any hex dump is allowed


field [0] VideotexString DEFAULT "313233"

VisibleString

any 7-bit ASCII character (between 0x20 and 0x7E) string


field [0] VisibleString DEFAULT "Hello"

ASN1Parse does not support the following features:

  • Indirect default values
  • Lists of default values
  • Default values for containers

The following table shows an example of unsupported default values:


myDefault INTEGER ::= 4

TEST ::= SEQUENCE
{
	aaa [0] INTEGER DEFAULT myDefault,         -- indirect default
	bbb [1] SEQUENCE OF INTEGER DEFAULT { 3 }, -- list of defaults
	ccc [2] SUB DEFAULT { 2, TRUE }            -- container default
}

SUB ::= SEQUENCE
{
	a [0] INTEGER,
	b [1] BOOLEAN,
	...
}

If your ASN.1 grammar has unsupported default values, the sc compiler prints warning messages, like the ones in the following sample output:


CDISP9163W WARNING: repeatable ASN.1 field 'xxx' has DEFAULT list '{ 1, 3 }', which is ignored because it is not yet supported
CDISP9163W WARNING: ASN.1 field 'yyy' has a default value of '{ 2, TRUE }' specified in the grammar, which could not be automatically converted to a Streams literal of type 'int64'. Be aware that a non-existing ASN.1 value results in an empty result list.

Resolving the problem

If you have ignored default values, you can implement the default handling in a downstream operator. For example, if a list is empty but default values should be applied, insert the default element.