---
name: "libressl-i2a_ASN1_STRING"
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-i2a_ASN1_STRING"
---

# libressl-i2a\_ASN1\_STRING(3)

hexadecimal dump of an ASN.1 string

## NAME

**i2a\_ASN1\_STRING**, **i2a\_ASN1\_INTEGER**, **i2a\_ASN1\_ENUMERATED**, **a2i\_ASN1\_STRING**, **a2i\_ASN1\_INTEGER**, **a2i\_ASN1\_ENUMERATED** – hexadecimal dump of an ASN.1 string

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

*int*\

**i2a\_ASN1\_STRING**(*BIO \*out\_bio*, *const ASN1\_STRING \*a*, *int type*);

*int*\

**i2a\_ASN1\_INTEGER**(*BIO \*out\_bio*, *const ASN1\_INTEGER \*a*);

*int*\

**i2a\_ASN1\_ENUMERATED**(*BIO \*out\_bio*, *const i2a\_ASN1\_ENUMERATED \*a*);

*int*\

**a2i\_ASN1\_STRING**(*BIO \*in\_bio*, *ASN1\_STRING \*out\_string*, *char \*buffer*, *int size*);

*int*\

**a2i\_ASN1\_INTEGER**(*BIO \*in\_bio*, *ASN1\_INTEGER \*out\_string*, *char \*buffer*, *int size*);

*int*\

**a2i\_ASN1\_ENUMERATED**(*BIO \*in\_bio*, *ASN1\_ENUMERATED \*out\_string*, *char \*buffer*, *int size*);

## DESCRIPTION

The functions **i2a\_ASN1\_STRING**(), **i2a\_ASN1\_INTEGER**(), and **i2a\_ASN1\_ENUMERATED**() write a hexadecimal representation of *a* to *out\_bio*. The *type* argument is ignored.

Each byte of ASN1\_STRING\_get0\_data(3) is written as a number consisting of two upper-case hexadecimal digits. After each group of 70 digits, a backslash and a linefeed are inserted before the next digit.

If the ASN1\_STRING\_length(3) of *a* is 0, instead a pair of zero digits ("00") is written by **i2a\_ASN1\_INTEGER**() and **i2a\_ASN1\_ENUMERATED**() and a single zero digit ("0") by **i2a\_ASN1\_STRING**(). If *a* is a NULL pointer, nothing is written.

If *a* represents a negative integer, **i2a\_ASN1\_INTEGER**() prepends a minus sign to the output.

The functions **a2i\_ASN1\_STRING**(), **a2i\_ASN1\_INTEGER**(), and **a2i\_ASN1\_ENUMERATED**() parse a hexadecimal representation of an ASN.1 string into *out\_string*. Both lower-case and upper-case hexadecimal digits are accepted. Every pair of input digits is converted into one output byte.

On every input line, the trailing newline character and an optional carriage return character preceding it are ignored. The trailing newline need not be present on the last line. If there is a backslash character before the newline character, parsing is continued on the next input line.

At least one pair of input digits is required by **a2i\_ASN1\_INTEGER**() and **a2i\_ASN1\_ENUMERATED**(), whereas **a2i\_ASN1\_STRING**() converts empty input to an empty string.

These functions are able to parse the output of **i2a\_ASN1\_ENUMERATED**(). They can parse the output of **i2a\_ASN1\_INTEGER**() unless *a* was negative, and they can parse the output of **i2a\_ASN1\_STRING**() unless the ASN1\_STRING\_length(3) of *a* was 0.

Parsing fails if an input line contains an odd number of input digits or if memory allocation fails.

These functions use the *buffer* provided by the caller and assume it is at least *size* bytes long. It is unspecified what the buffer contains after the functions return.

## RETURN VALUES

The functions **i2a\_ASN1\_STRING**(), **i2a\_ASN1\_INTEGER**(), and **i2a\_ASN1\_ENUMERATED**() return the number of bytes written or -1 if BIO\_write(3) fails. In particular, they all return 0 when *a* is a NULL pointer. **i2a\_ASN1\_STRING**() returns 1 for an empty string or an even number greater than 1 for a string that is not empty. **i2a\_ASN1\_INTEGER**() returns an even number greater than 1 for positive input or an odd number greater than 2 for negative input. **i2a\_ASN1\_ENUMERATED**() always returns a non-negative even number when successful.

The functions **a2i\_ASN1\_STRING**(), **a2i\_ASN1\_INTEGER**(), and **a2i\_ASN1\_ENUMERATED**() are intended to return 1 for success or 0 for failure, but see the BUGS section for a number of traps.

## SEE ALSO

a2i\_ipadd(3), ASN1\_STRING\_length(3), ASN1\_STRING\_new(3), ASN1\_STRING\_print\_ex(3), i2a\_ASN1\_OBJECT(3), i2s\_ASN1\_INTEGER(3)

## HISTORY

**i2a\_ASN1\_INTEGER**() and **a2i\_ASN1\_INTEGER**() first appeared in SSLeay 0.6.0. **i2a\_ASN1\_STRING**() and **a2i\_ASN1\_STRING**() first appeared in SSLeay 0.6.5. **a2i\_ASN1\_STRING**() has been part of the public API since SSLeay 0.6.5 and **i2a\_ASN1\_STRING**() since SSLeay 0.8.0. These functions have been available since OpenBSD 2.4.

**i2a\_ASN1\_ENUMERATED**() and **a2i\_ASN1\_ENUMERATED**() first appeared in OpenSSL 0.9.2 and have been available since OpenBSD 2.6.

## BUGS

If the first call to BIO\_gets(3) does not return any data, even if that is caused by a fatal I/O error, if the BIO type does not support the “gets” operation, or if it is caused by the BIO being non-blocking, **a2i\_ASN1\_STRING**() immediately succeeds and returns an empty *out\_string*.

If **BIO\_gets**(*3*) returns a partial line, for example because the given *size* is insufficient to contain one of the input lines or for reasons specific to the BIO type, **a2i\_ASN1\_STRING**(), **a2i\_ASN1\_INTEGER**(), and **a2i\_ASN1\_ENUMERATED**() may fail or silently return a truncated result. The caller is responsible for providing a *buffer* of sufficient size to contain the longest possible input line and for choosing a BIO of a type that only returns complete input lines and does not perform partial reads.

The functions **a2i\_ASN1\_STRING**(), **a2i\_ASN1\_INTEGER**(), and **a2i\_ASN1\_ENUMERATED**() do not support non-blocking BIOs. Reading is terminated as soon as BIO\_gets(3) returns a value less than 1.
