TOP

OSS TLV (Type-Length-Value) Print Utility

Introduction

The OSS TLV Print Utility, osstlv ( osstlv.exe on Windows), is a program that takes a BER, DER, or CER encoding in ASCII or binary format from an input file and writes it to an output file in one of three different type-length-value (TLV) formats.

BER/DER/CER encodings can be printed in any one of the following formats: hexadecimal-TLV, decomposed-TLV, or syntax-TLV. These formats are described in TLV Formats below.

NOTE: OSS TLV is only available on common platforms like Linux, Windows, and Solaris, and may not be available for your embedded system port. If you are interested in OSS TLV for your platform, contact OSS Nokalva Sales.

Using the OSS TLV Print Utility

Command Line

osstlv [-b|-t] <input> [+off[,num]] [-dec|-hex|-syn] [-out <output>] [-notitles] [-noaddition] [-pad <byte>] [-noshort]
                       [-nocdrheaders] [-help]

Options

Keyword options, except -help, can be abbreviated to the fewest number of letters needed to uniquely identify them. For example, -binary can be abbreviated to -b.

-binary infile
The infile input file contains a BER/DER/CER encoding in binary format. If infile is a dash (e.g., -b -), then the input is read from stdin. -binary is the default input format when the input file name is specified without being preceded by either the -binary or -text option.
-text infile
The infile input file contains a BER/DER/CER encoding in hexadecimal format. If infile is a dash (e.g., -t -) then the input is read from stdin.
+offset,num
Print a number of bytes, num, of a BER/DER/CER encoding from an input file starting from the offset position.
-hexadecimal
Print a BER/DER/CER encoding in hexadecimal-TLV format. This is the default output format.
-decomposed
Print a BER/DER/CER encoding in decomposed-TLV format.
-syntax
Print a BER/DER/CER encoding in syntax-TLV format.
-nocdrheaders
Do not automatically detect and skip CDR headers in the input encoding. By default, automatic detection is enabled.
-output outfile
Output will be written to the outfile file. Output is written to stdout when the -output option is omitted. If outfile is a dash (e.g., -o -) then the output file name is read from stdin.
-noshort
Do not truncate output lines that would otherwise be longer than a line. By default, such lines are truncated to fit one line without wrapping.
-notitles
Do not print the "Type", "Length", and "Contents" titles when printing a BER/DER/CER encoding in syntax-TLV format. By default, titles are printed.
-noaddition
Do not print additional clarifying values for INTEGER and REAL types when printing in decomposed-TLV or syntax-TLV formats, see the third example below. Use this option when the output will be parsed and you want output lines that follow the same pattern, regardless of type. By default, additional values are printed.
-help
Print help information.
-pad <byte>
Skip padding areas between concatenated records filled with <byte>s. < byte> represents a hex number (e.g., 0x00 for hex 00, 0xFF for hex FF) or a non-negative decimal number from 0 to 255 (e.g., 10 or 128).

Examples

  • Print the BER/DER/CER binary file, foo.dat, in hexadecimal-TLV format to out.txt without truncating output lines:
    osstlv -b foo.dat -nos -o out.txt

  • Print the BER/DER/CER text file, foo.txt, in syntax-TLV format to stdout without printing titles:
    osstlv -t foo.txt -s -noa

  • Print the BER/DER/CER binary file, foo.dat, in decomposed-TLV format without printing additional hexadecimal values for INTEGER and REAL types:
    osstlv -b foo.dat -d -noa
    Without -noa a line can be printed as:
    18:d= 3 hl=2 l=   9 prim: REAL       :{2365,10,28} (2.365000E+031)
    With -noa the same line would be printed as:
    18:d= 3 hl=2 l=   9 prim: REAL       :{2365,10,28}

  • Print the contents of the BER/DER/CER binary file, foo.dat, containing 2 concatenated records with zero padding bytes in hexadecimal format, skipping padding bytes:
    osstlv foo.dat -pad 0x00
    
       30 80
          A1 80
          00 00
       00 00
    
       Padding byte '0x00' detected, skipping 6 bytes ...
    
       000000000000
    
       Concatenated record #2 detected, printing ...
    
       30 80
          A1 80
          00 00
       00 00
    
       Padding byte '0x00' detected, skipping 6 bytes ...
    
       000000000000

TLV Formats

BER/DER/CER encodings can be printed in any one of the following formats:

Hexadecimal-TLV Format

View a BER/DER/CER encoding in hexadecimal format with type, length, and value information separated from each other by spaces or newlines. All nested encodings are printed in an indented manner. Length values of 80 (hex) are not the true length of the value, but indicate that the encoding is indefinite in length, and that the occurrence of matching end-of-contents octets (00 00) indicates the end of the value.

Example

Definite length encoding:

   30 2A
       30 06
           02 01 0A
           01 01 FF
       30 00
       30 1E
           09 09 803509540A2BE520DF
           17 11 3932303432333137343333342D30373030

Indefinite length encoding:

   30 80
       30 80
           02 01 0A
           01 01 FF
           00 00
       30 80
           00 00
       30 80
           09 09 803509540A2BE520DF
           17 11 3932303432333137343333342D30373030
           00 00
       00 00

Decomposed-TLV format

View a BER/DER/CER encoding in a format that lends itself to post-processing. The structure of each output line is

<offset>:d=<lvl> hl=<head> l=<len> {prim | cons}: <type> :<contents>

where

offset
is the offset from the beginning of the message.
lvl
is the level of nesting; 1 is the outermost level.
head
is the number of octets occupied by the header information (type and length fields) of an encoding. If an input value is misencoded and the length of a tag-length pair is greater than the remaining data length, three question marks, ???, are printed in this field.
len
is the decimal length of an encoding; -128 is for encodings with an indefinite length. If an input value is misencoded and a length value exceeds the remaining data length, the remaining data length is printed with a question mark, for example, ?35. If an input value is so misencoded that the length cannot be found, three question marks are printed: ???.
type
is the built-in name of an ASN.1 type when the type information contains a UNIVERSAL class, otherwise it is the tag class and number in brackets. The tag class is printed only for APPLICATION and PRIVATE classes; it is not printed for context-specific classes. For encodings with an indefinite length, END-OF-CONTENTS is printed when the end of the current encoding is reached. The type information is prefixed with either prim:, indicating that the type is a primitive one, or cons:, indicating that it is a constructed one (i.e., it contains zero or more types, lengths, and values nested within.)
contents
is the value component of the encoding. The contents field is present only when the encoding is primitive. If an error occurs when converting a primitive encoding value, its contents are printed as a hexadecimal string.

Example

Definite length encoding:

    0:d= 1 hl=2 l=  42 cons: SET
    2:d= 2 hl=2 l=   6 cons: SET
    4:d= 3 hl=2 l=   1 prim: INTEGER      :10 (0x0a)
    7:d= 3 hl=2 l=   1 prim: BOOLEAN      :TRUE
   10:d= 2 hl=2 l=   0 cons: SET
   12:d= 2 hl=2 l=  30 cons: SET
   14:d= 3 hl=2 l=   9 prim: REAL         :{2365,10,28} (2.365000E+031)
   25:d= 3 hl=2 l=  17 prim: UTCTime      :920423174334-0700

Indefinite length encoding:

    0:d= 1 hl=2 l=-128 cons: SET
    2:d= 2 hl=2 l=-128 cons: SET
    4:d= 3 hl=2 l=   1 prim: INTEGER      :10 (0x0a)
    7:d= 3 hl=2 l=   1 prim: BOOLEAN      :TRUE
   10:d= 3 hl=2 l=   0 prim: END-OF-CONTENTS
   12:d= 2 hl=2 l=-128 cons: SET
   14:d= 3 hl=2 l=   0 prim: END-OF-CONTENTS
   16:d= 2 hl=2 l=-128 cons: SET
   18:d= 3 hl=2 l=   9 prim: REAL         :{2365,10,28} (2.365000E+031)
   29:d= 3 hl=2 l=  17 prim: UTCTime      :920423174334-0700
   48:d= 3 hl=2 l=   0 prim: END-OF-CONTENTS
   50:d= 2 hl=2 l=   0 prim: END-OF-CONTENTS

Syntax-TLV format

Outputs Type, Length, and Contents fields that are similar to the format used in X.690 to show examples of encodings, where

Type
is the name of the ASN.1 type, if this can be determined, otherwise it is the tag class and number of the encoding.
Length
is the length of the encoding or indef for indefinite length encodings. If an input value is misencoded and a length value exceeds the remaining data length, the remaining data length is printed with a question mark, for example, ?35 . If an input value is so misencoded that the length cannot be found, three question marks are printed: ???.
Contents
is the contents if the encoding is primitive, or empty for constructed encodings.

Example

Definite length encoding:

    Type         Length  Contents
    SET          42
        Type         Length  Contents
        SET          6
             Type         Length  Contents
             INTEGER      1       10 (0x0a)
             BOOLEAN      1       TRUE
        SET          0
        SET          30
            Type         Length  Contents
            REAL         9       {2365,10,28} (2.365000E+031)
            UTCTime      17      920423174334-0700

Indefinite length encoding:

    Type         Length  Contents
    SET          indef
        Type         Length  Contents
        SET          indef
            Type         Length  Contents
            INTEGER      1       10 (0x0a)
            BOOLEAN      1       TRUE
            END-OF-CONTENTS
        SET          indef
                     END-OF-CONTENTS
        SET          indef
            Type         Length  Contents
            REAL         9       {2365,10,28} (2.365000E+031)
            UTCTime      17      920423174334-0700
            END-OF-CONTENTS
        END-OF-CONTENTS

Error Messages

One of the following error messages is generated when an error occurs while parsing the command line:

  • Error opening input file, foo.txt. No such file or directory.
  • Error opening output file, foo.out.
  • Error reading input file, foo.dat.
  • Error reading, stdin.
  • Input file name is missing.
  • Too many input file names.
  • Output file name is missing.
  • Too many output file names.
  • Input text file, foo.txt, contains non-hexadecimal characters.
  • Invalid number of bytes to be read from input file, 12bb45.
  • Invalid offset into input file, 12aa67.
  • Missing mandatory input file name.
  • Output file name is missing.
  • Unidentified input parameter, -foo."
  • The -pad option requires a mandatory parameter <byte>.
  • Invalid unsigned hexadecimal number, 'xx'.

One of the following error messages is generated when an error occurs while parsing an input BER/DER/CER encoding:

  • Value misencoded: premature end of input encoding encountered.
  • Value misencoded, length, nnn (0xff), longer than remaining data length, mmm (0xgg):
  • Value misencoded: expected EOC octets not found for indefinite length encoding.
  • Value misencoded, EOC with non-zero second octet encountered.
  • Value misencoded, length of a tag-length pair, nnn (0xff), longer than remaining data length, mmm (0xgg):

This documentation applies to the latest versions of the OSS® ASN.1 Tools software.

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 the OSS® ASN.1 Tools is associated with a specific license and related unique license number. That license determines, among other things, what functions of the OSS ASN.1 Tools are available to you.