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

# libressl-s2i\_ASN1\_INTEGER(3)

ASN.1 data type conversion utilities for certificate extensions

## NAME

**i2s\_ASN1\_ENUMERATED**, **i2s\_ASN1\_ENUMERATED\_TABLE**, **i2s\_ASN1\_INTEGER**, **s2i\_ASN1\_INTEGER**, **i2s\_ASN1\_OCTET\_STRING**, **s2i\_ASN1\_OCTET\_STRING** – ASN.1 data type conversion utilities for certificate extensions

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

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

*char* *\**\

**i2s\_ASN1\_ENUMERATED**(*X509V3\_EXT\_METHOD \*method*, *const ASN1\_ENUMERATED \*a*);

*char* *\**\

**i2s\_ASN1\_INTEGER**(*X509V3\_EXT\_METHOD \*method*, *const ASN1\_INTEGER \*a*);

*ASN1\_INTEGER* *\**\

**s2i\_ASN1\_INTEGER**(*X509V3\_EXT\_METHOD \*method*, *const char \*value*);

*char* *\**\

**i2s\_ASN1\_OCTET\_STRING**(*X509V3\_EXT\_METHOD \*method*, *const ASN1\_OCTET\_STRING \*aos*);

*ASN1\_OCTET\_STRING* *\**\

**s2i\_ASN1\_OCTET\_STRING**(*X509V3\_EXT\_METHOD \*method*, *X509V3\_CTX \*ctx*, *const char \*value*);

*char* *\**\

**i2s\_ASN1\_ENUMERATED\_TABLE**(*X509V3\_EXT\_METHOD \*method*, *const ASN1\_ENUMERATED \*a*);

## DESCRIPTION

These functions convert to and from *ASN1\_ENUMERATED*, *ASN1\_INTEGER*, and *ASN1\_OCTET\_STRING* objects. They are primarily used internally for parsing configuration files and displaying X.509v3 certificate extensions. With the exception of **i2s\_ASN1\_ENUMERATED\_TABLE**(), these functions ignore the *method* argument. Any object or string returned by these functions must be freed by the caller.

**i2s\_ASN1\_ENUMERATED**() and **i2s\_ASN1\_INTEGER**() first convert *a* into a *BIGNUM* object with ASN1\_ENUMERATED\_to\_BN(3) or ASN1\_INTEGER\_to\_BN(3) and then derive a string representation using BN\_bn2dec(3) or BN\_bn2hex(3). Decimal representation is used if the number has less than 128 bits, otherwise hexadecimal representation is used to avoid excessive conversion cost.

**s2i\_ASN1\_INTEGER**() converts the NUL-terminated decimal or hexadecimal string representation of an integer in *value* into an *ASN1\_INTEGER* object. A sign prefix of ‘-’ indicates a negative number and the base prefixes ‘0x’ and ‘0X’ indicate hexadecimal representation, otherwise decimal representation is assumed. After skipping the sign and base prefixes, an intermediate conversion into a *BIGNUM* is performed using BN\_dec2bn(3) or BN\_hex2bn(3) and the *ASN1\_INTEGER* is then obtained with BN\_to\_ASN1\_INTEGER(3).

**i2s\_ASN1\_OCTET\_STRING**() converts the octets in *aos* into a string where the octets are colon-separated and represented as pairs of uppercase hexadecimal digits.

**s2i\_ASN1\_OCTET\_STRING**() converts the NUL-terminated string *str* into an *ASN1\_OCTET\_STRING*. The *method* and *ctx* arguments are ignored. Every pair of hexadecimal digits is converted into an octet. Colons are ignored if they are at the start, the end or if they separate two pairs of digits.

**i2s\_ASN1\_ENUMERATED\_TABLE**() looks up the value of *a* in the *usr\_data* field of the non-NULL *method* and returns a copy of the associated long name. If no match is found, *a* is passed to **i2s\_ASN1\_ENUMERATED**(). The *method* argument can be provided by application programs or it can be a default method obtained from X509V3\_EXT\_get\_nid(3). The default *methods* corresponding to the following *nid* arguments have strings configured in their *usr\_data* field:

| | |
| --- | --- |
| NID\_crl\_reason | reason codes, RFC 5280, 5.3.1 |
| NID\_key\_usage | key usage, RFC 5280, 4.2.1.3 |
| NID\_netscape\_cert\_type | Netscape certificate type (obsolete) |

## RETURN VALUES

**i2s\_ASN1\_ENUMERATED**(), **i2s\_ASN1\_ENUMERATED\_TABLE**(), **i2s\_ASN1\_INTEGER**(), and **i2s\_ASN1\_OCTET\_STRING**() return a NUL-terminated string, or NULL on memory allocation failure.

**s2i\_ASN1\_INTEGER**() returns an *ASN1\_INTEGER*, or NULL on error. Error conditions are memory allocation failure or if *value* is not a valid decimal or hexadecimal encoding of an integer.

**s2i\_ASN1\_OCTET\_STRING**() returns an *ASN1\_OCTET\_STRING*, or NULL on error. Error conditions are memory allocation failure or if *value* contains an odd number of hexadecimal digits or anything except colons at the start, the end or between pairs of hexadecimal digits.

Error codes can sometimes be obtained by ERR\_get\_error(3).

## SEE ALSO

a2i\_ASN1\_INTEGER(3), a2i\_ipadd(3), ASN1\_INTEGER\_new(3), ASN1\_INTEGER\_to\_BN(3), ASN1\_OCTET\_STRING\_new(3), [crypto(3)](/crypto/3.md), v2i\_ASN1\_BIT\_STRING(3), X509V3\_get\_d2i(3)

## HISTORY

These functions first appeared in OpenSSL 0.9.4 and have been available since OpenBSD 2.6.

## BUGS

Of these functions at least **i2s\_ASN1\_ENUMERATED\_TABLE**() can succeed while setting an error and fail without setting an error on the error stack.
