ASN-1Step supports conversion of ASN.1 messages to and from CSV (Comma-Separated Values) format. To represent a structured ASN.1 message in CSV format, ASN-1Step flattens it into a fixed number of columns by recursively expanding complex SET, SEQUENCE, and CHOICE types up to the innermost fields with simple ASN.1 types. The resulting record includes a place for each simple type value, which can be empty for optional fields with absent values.
ASN-1Step supports two CSV formats, as follows:
The CSV format can include an optional CSV header created by parsing the input PDU type definition. The header record consists of complete absolute references or single ASN.1 names that match the values in the rows or columns. The column values are generated by parsing encoded messages or value notation.
ASN.1 type notation
PersonnelRecord ::= SEQUENCE { name PrintableString, number INTEGER OPTIONAL, children SEQUENCE OF ChildInformation } ChildInformation ::= SET { name PrintableString, date GeneralizedTime OPTIONAL }
ASN.1 value notation
value PersonnelRecord ::= { name "Nancy", number 20, children { {name "James", date "20020312000000"}, {name "Martha", date "20100820000000"} } }
CSV row format
name,number,children_name,children_date "Nancy",20,"James",03/12/02 00:00:00 "Nancy",20,"Martha",08/20/10 00:00:00
There are some restrictions imposed on CSV conversion because
These restrictions are as follows:
ASN.1 value: ErrorEntry ::= SEQUENCE { errorCode ERROR-CLASS.&code ({ErrorSet}), errorInfo ERROR-CLASS.&Type ({ErrorSet}{@.errorCode}) } e ErrorEntry ::= { errorCode 10, errorInfo Int : 20} CSV: errorCode,errorInfo(Int) 10,20
ASN.1 Value: myLabelUtf8 LabelUtf8 ::= "Umlaute: äÄöÖüÜ" CSV in text format: LabelUtf8 "Umlaute: \xc3\xa4\xc3\x84\xc3\xb6\xc3\x96\xc3\xbc\xc3\x9c"
CSVs are in human-readable format similar to ASN.1 value notation. The following table shows differences sorted by ASN.1 type. Additional representations are available for CSVs by passing special flags to the -csv option.
ASN.1 Type | ASN.1 Value | CSV Value |
---|---|---|
BIT STRING | bstring '0101011'B |
xmlbstring 010101 |
BOOLEAN | TRUE or FALSE | XML boolean extended items TRUE or FALSE 1 or 0 |
Restricted Character String types | Quoted cstring or list notation | Quoted strings UTF-8 encoding is used for Unicode characters; a special C-style character escape sequence \x## is used in the CSV text format. |
CHOICE | The selected alternative name is included as "chosen : <value>" | All alternatives are present, the ones that are not chosen have empty values with extra separators for all their nested components. |
ENUMERATED | identifier | identifier number |
GeneralizedTime | "20120808131347+0500" | The same non-quoted value One of these time stamp formats: 06/01/00 00:00:00 2007-11-07 11:36:49 |
NULL | NULL | NULL |
OBJECT IDENTIFIER, RELATIVE-OID | {arc1(num1) arc2 ... } or encoded format | Dot notation: 1.3.6.1.4.1.1900 |
OCTET STRINGS | hstring '6B646F726C793031'H |
xmlhstring 6B646F726C793031 BCD or TBCD ASCII format: kdorly01 |
Open Type | Either encoded or automatically decoded | Automatically decoded only if the full CSV header is present. XML format Hexadecimal format |
Types with Contents Constraint | bstring automatically decoded |
Automatically decoded if the containing PDU is known. |
REAL | Different representations, including {mantissa, base, exponent} notation | Decimal format |
SET, SEQUENCE | Values for fields with OPTIONAL/DEFAULT can be absent. | Columns for all fields with all their nested components are present. Missing values for optional fields are marked with extra separators. |
SET OF, SEQUENCE OF | Component values are included in {val1, val2, ...} |
One column is present for only one component. The row for the complete PDU is repeated for each extra component. |
TIME, DATE and other time types | "2010-04-15T17:18:18-07:00" | The same quoted value |
UTCTime | "200808131347Z" | The same non-quoted value |
Circularly defined types | Values for nested types are printed. | CSVs for nested recursions are created only when the full CSV header is present. |
Fields marked with the ASN1.Remove directive | Ignored | Ignored without extra column separators |
Conversion of OCTET STRING type values to and from ASCII, BCD, or TBCD format is supported using the -csv option with the ascii, bcd, or tbcd parameter, or by using the OSS.PrintFunctionName directive with an OSS-specific function name for that conversion, for example "ossPrintOctetAsBCDString" for a BCD conversion. Applying the OSS.PrintFunctionName directive to OCTET STRING types converts their values to or from the specified format. For example, you can mark OCTET STRING types for conversion to TBCD, BCD, ASCII, IP address, or a special time stamp format using the following directives:
--<OSS.PrintFunctionName MOD.Seq.*.soctVarBcd "ossPrintOctetAsBCDString">-- --<OSS.PrintFunctionName MOD.Seq.*.soctVarTbcd "ossPrintOctetAsTBCDString">-- --<OSS.PrintFunctionName MOD.Seq.*.soctVarIp "ossPrintOctetAsIPAddress">-- --<OSS.PrintFunctionName MOD.Seq.*.soctVarAsc "ossPrintOctetAsASCII">-- --<OSS.PrintFunctionName MOD.Seq.*.soctVarTime "ossPrintOctetAsTimeStamp">--
If the -csv option containing the ascii, bcd, or tbcd parameter is specified, the type values to which the directives are applied will not be affected. However, other OCTET STRING type values will be converted to the format specified in the -csv option.
When using ASCII to convert an OCTET STRING hstring value that starts with one or more space characters (20), the resulting CSV value is enclosed in quotation marks, which indicates that spaces are part of the value. When decoding, ASN-1Step ignores quotation marks that follow space characters.
Example
ASN.1: Oct ::= OCTET STRING oct Oct ::= '20206C65616469616720737061636573'H CSV: Oct " leading spaces"
This documentation applies to release 10.5 and later of ASN-1Step®.
Copyright © 2024 OSS Nokalva, Inc. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means electronic, mechanical, photocopying, recording or otherwise, without the prior permission of OSS Nokalva, Inc.
Every distributed copy of ASN-1Step is associated with a specific license and related unique license number. That license determines, among other things, what functions of ASN-1Step are available to you.