---
name: "libressl-ASN1_parse_dump"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-ASN1_parse_dump"
---

# libressl-ASN1\_parse\_dump(3)

parse BER and print information about it

## NAME

**ASN1\_parse\_dump**, **ASN1\_parse** – parse BER and print information about it

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/asn1.h\>**

*int*\

**ASN1\_parse\_dump**(*BIO \*bio*, *const unsigned char \*ber\_in*, *long length*, *int indent*, *int dump*);

*int*\

**ASN1\_parse**(*BIO \*bio*, *const unsigned char \*ber\_in*, *long length*, *int indent*);

## DESCRIPTION

**ASN1\_parse\_dump**() parses BER-encoded values and prints information about them to *bio*. On function entry, \**ber\_in* is expected to point to the first identifier octet of an encoded value. At most *length* bytes are inspected.

For each value successfully parsed, the following information is printed:

1. The index of its first identifier octet relative to *ber\_in* as a decimal number followed by a colon. For the first value parsed and printed, this is "0:".

2. The nesting depth as a decimal integer. For the first value parsed and printed, this is "d=0".

3. The header length in bytes, including the identifier octets and the length octets, as a decimal integer. For example, for a boolean value, this is "hl=2" because the encoding of a boolean value contains one identifier octet (0x01) and one length octet (also 0x01, because one content octet follows after the header).

4. If the value is encoded using the definite form for the length octets, the number encoded in the length octets as a decimal integer. This is the number of content octets that follow. For example, for a boolean value, this is "l=1". If the value is encoded using a length octet indicating the indefinite form, "l=inf" is printed instead.

5. If the value is primitive, "prim:" is printed; if it is constructed, "cons:".

6. The next field depends on the class of the tag:

   - V\_ASN1\_PRIVATE

     "priv" followed by the decimal tag number in square brackets

   - V\_ASN1\_CONTEXT\_SPECIFIC

     "cont" followed by the decimal tag number in square brackets

   - V\_ASN1\_APPLICATION

     "appl" followed by the decimal tag number in square brackets

   - V\_ASN1\_UNIVERSAL

     If the tag number is 30 or less, the return value from ASN1\_tag2str(3) is printed; otherwise, "\<ASN1" followed by the decimal tag number and a closing angle bracket.

For constructed values, the contained values are recursively printed.

Primitive values are processed as follows:

- V\_ASN1\_BOOLEAN

  Its integer value is printed as a decimal number.

- V\_ASN1\_INTEGER

  Decoded with d2i\_ASN1\_INTEGER(3), printed as a hexadecimal number with an even number of digits.

- V\_ASN1\_ENUMERATED

  Decoded with d2i\_ASN1\_ENUMERATED(3), printed as a hexadecimal number with an even number of digits.

- V\_ASN1\_OBJECT

  Decoded with d2i\_ASN1\_OBJECT(3), printed with i2a\_ASN1\_OBJECT(3).

- V\_ASN1\_OCTET\_STRING

  Decoded with d2i\_ASN1\_OCTET\_STRING(3). If the data consists only of printable ASCII characters, line feeds, carriage returns and horizontal tabs, it is printed as an ASCII string.

  Otherwise, the *dump* argument decides the format. If it is zero, a raw hex dump is emitted, consisting of two hexadecimal digits for every data byte. If *dump* is non-zero, BIO\_dump\_indent(3) is used. Unless *dump* is -1, the data is truncated after *dump* bytes.

- V\_ASN1\_PRINTABLESTRING

  Printed as an ASCII string. The same applies to V\_ASN1\_IA5STRING, V\_ASN1\_T61STRING, V\_ASN1\_NUMERICSTRING, V\_ASN1\_VISIBLESTRING, V\_ASN1\_UTF8STRING, V\_ASN1\_UTCTIME, and V\_ASN1\_GENERALIZEDTIME.

- Other tags

  If the *dump* argument is 0, their data is silently ignored. If *dump* is non-zero, BIO\_dump\_indent(3) is used. Unless *dump* is -1, the data is truncated after *dump* bytes.

**ASN1\_parse**() is identical to **ASN1\_parse\_dump**() with 0 passed as the *dump* argument.

## RETURN VALUES

These functions normally return 1 for success or 0 for failure; when printing indefinite-length encoded BER with a tag of class V\_ASN1\_UNIVERSAL, the return value 2 indicates that the printing stopped when reaching the end-of-content marker.

In particular, they print an error message to *bio*, abort parsing and printing, and return 0 when parsing or decoding fails, when a recursive call fails, when encountering a value extending beyond *length*, or when encountering a nesting level in excess of 128. They also abort parsing and printing and return 0 when any printing operation fails.

## SEE ALSO

ASN1\_get\_object(3), ASN1\_item\_d2i(3), ASN1\_item\_new(3), ASN1\_STRING\_print(3), ASN1\_TYPE\_new(3)

## STANDARDS

ITU-T Recommendation X.690, also known as ISO/IEC 8825-1: Information technology - ASN.1 encoding rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER), section 8.1: General rules for encoding

## HISTORY

**ASN1\_parse**() first appeared in SSLeay 0.5.1 and has been available since OpenBSD 2.4.

**ASN1\_parse\_dump**() first appeared in OpenSSL 0.9.6 and has been available since OpenBSD 2.9.

## BUGS

The content of values tagged as V\_ASN1\_BMPSTRING is silently ignored and none of it is printed.
