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

# libressl-d2i\_ASN1\_OCTET\_STRING(3)

decode and encode ASN1\_STRING objects

## NAME

**d2i\_ASN1\_OCTET\_STRING**, **i2d\_ASN1\_OCTET\_STRING**, **d2i\_ASN1\_BIT\_STRING**, **i2d\_ASN1\_BIT\_STRING**, **d2i\_ASN1\_INTEGER**, **i2d\_ASN1\_INTEGER**, **d2i\_ASN1\_UINTEGER**, **d2i\_ASN1\_ENUMERATED**, **i2d\_ASN1\_ENUMERATED**, **d2i\_ASN1\_UTF8STRING**, **i2d\_ASN1\_UTF8STRING**, **d2i\_ASN1\_IA5STRING**, **i2d\_ASN1\_IA5STRING**, **d2i\_ASN1\_UNIVERSALSTRING**, **i2d\_ASN1\_UNIVERSALSTRING**, **d2i\_ASN1\_BMPSTRING**, **i2d\_ASN1\_BMPSTRING**, **d2i\_ASN1\_GENERALSTRING**, **i2d\_ASN1\_GENERALSTRING**, **d2i\_ASN1\_T61STRING**, **i2d\_ASN1\_T61STRING**, **d2i\_ASN1\_VISIBLESTRING**, **i2d\_ASN1\_VISIBLESTRING**, **d2i\_ASN1\_PRINTABLESTRING**, **i2d\_ASN1\_PRINTABLESTRING**, **d2i\_ASN1\_PRINTABLE**, **i2d\_ASN1\_PRINTABLE**, **d2i\_DIRECTORYSTRING**, **i2d\_DIRECTORYSTRING**, **d2i\_DISPLAYTEXT**, **i2d\_DISPLAYTEXT**, **d2i\_ASN1\_GENERALIZEDTIME**, **i2d\_ASN1\_GENERALIZEDTIME**, **d2i\_ASN1\_UTCTIME**, **i2d\_ASN1\_UTCTIME**, **d2i\_ASN1\_TIME**, **i2d\_ASN1\_TIME** – decode and encode ASN1\_STRING objects

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

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

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

**d2i\_ASN1\_OCTET\_STRING**(*ASN1\_OCTET\_STRING \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_OCTET\_STRING**(*ASN1\_OCTET\_STRING \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_BIT\_STRING* *\**\

**d2i\_ASN1\_BIT\_STRING**(*ASN1\_BIT\_STRING \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_BIT\_STRING**(*ASN1\_BIT\_STRING \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_INTEGER* *\**\

**d2i\_ASN1\_INTEGER**(*ASN1\_INTEGER \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_INTEGER**(*ASN1\_INTEGER \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_INTEGER* *\**\

**d2i\_ASN1\_UINTEGER**(*ASN1\_INTEGER \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*ASN1\_ENUMERATED* *\**\

**d2i\_ASN1\_ENUMERATED**(*ASN1\_ENUMERATED \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_ENUMERATED**(*ASN1\_ENUMERATED \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_UTF8STRING* *\**\

**d2i\_ASN1\_UTF8STRING**(*ASN1\_UTF8STRING \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_UTF8STRING**(*ASN1\_UTF8STRING \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_IA5STRING* *\**\

**d2i\_ASN1\_IA5STRING**(*ASN1\_IA5STRING \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_IA5STRING**(*ASN1\_IA5STRING \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_UNIVERSALSTRING* *\**\

**d2i\_ASN1\_UNIVERSALSTRING**(*ASN1\_UNIVERSALSTRING \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_UNIVERSALSTRING**(*ASN1\_UNIVERSALSTRING \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_BMPSTRING* *\**\

**d2i\_ASN1\_BMPSTRING**(*ASN1\_BMPSTRING \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_BMPSTRING**(*ASN1\_BMPSTRING \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_GENERALSTRING* *\**\

**d2i\_ASN1\_GENERALSTRING**(*ASN1\_GENERALSTRING \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_GENERALSTRING**(*ASN1\_GENERALSTRING \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_T61STRING* *\**\

**d2i\_ASN1\_T61STRING**(*ASN1\_T61STRING \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_T61STRING**(*ASN1\_T61STRING \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_VISIBLESTRING* *\**\

**d2i\_ASN1\_VISIBLESTRING**(*ASN1\_VISIBLESTRING \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_VISIBLESTRING**(*ASN1\_VISIBLESTRING \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_PRINTABLESTRING* *\**\

**d2i\_ASN1\_PRINTABLESTRING**(*ASN1\_PRINTABLESTRING \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_PRINTABLESTRING**(*ASN1\_PRINTABLESTRING \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_STRING* *\**\

**d2i\_ASN1\_PRINTABLE**(*ASN1\_STRING \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_PRINTABLE**(*ASN1\_STRING \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_STRING* *\**\

**d2i\_DIRECTORYSTRING**(*ASN1\_STRING \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_DIRECTORYSTRING**(*ASN1\_STRING \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_STRING* *\**\

**d2i\_DISPLAYTEXT**(*ASN1\_STRING \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_DISPLAYTEXT**(*ASN1\_STRING \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_GENERALIZEDTIME* *\**\

**d2i\_ASN1\_GENERALIZEDTIME**(*ASN1\_GENERALIZEDTIME \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_GENERALIZEDTIME**(*ASN1\_GENERALIZEDTIME \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_UTCTIME* *\**\

**d2i\_ASN1\_UTCTIME**(*ASN1\_UTCTIME \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_UTCTIME**(*ASN1\_UTCTIME \*val\_in*, *unsigned char \*\*der\_out*);

*ASN1\_TIME* *\**\

**d2i\_ASN1\_TIME**(*ASN1\_TIME \*\*val\_out*, *const unsigned char \*\*der\_in*, *long length*);

*int*\

**i2d\_ASN1\_TIME**(*ASN1\_TIME \*val\_in*, *unsigned char \*\*der\_out*);

## DESCRIPTION

These functions decode and encode various ASN.1 built-in types that can be represented by *ASN1\_STRING* objects. For details about the semantics, examples, caveats, and bugs, see ASN1\_item\_d2i(3).

The format consists of one identifier byte, one or more length bytes, and one or more content bytes. The identifier bytes and corresponding ASN.1 types are as follows:

| | | |
| --- | --- | --- |
| *OpenSSL* *type* | *identifier* | *ASN.1* *type* |
|  |  |
| *ASN1\_OCTET\_STRING* | 0x04 | OCTET STRING |
| *ASN1\_BIT\_STRING* | 0x03 | BIT STRING |
| *ASN1\_INTEGER* | 0x02 | INTEGER |
| *ASN1\_ENUMERATED* | 0x0a | ENUMERATED |
| *ASN1\_UTF8STRING* | 0x0c | UTF8String |
| *ASN1\_IA5STRING* | 0x16 | IA5String |
| *ASN1\_UNIVERSALSTRING* | 0x1c | UniversalString |
| *ASN1\_BMPSTRING* | 0x1e | BMPString |
| *ASN1\_GENERALSTRING* | 0x1b | GeneralString |
| *ASN1\_T61STRING* | 0x14 | T61String |
| *ASN1\_VISIBLESTRING* | 0x1a | VisibleString |
| *ASN1\_PRINTABLESTRING* | 0x13 | PrintableString |
| *ASN1\_GENERALIZEDTIME* | 0x18 | GeneralizedTime |
| *ASN1\_UTCTIME* | 0x17 | UTCTime |

**d2i\_DIRECTORYSTRING**() and **i2d\_DIRECTORYSTRING**() decode and encode an ASN.1 *DirectoryString* structure defined in RFC 5280 section 4.1.2.4 and used for ASN.1 *EDIPartyName* structures; see EDIPARTYNAME\_new(3). When decoding, it accepts any of the types UTF8String, UniversalString, BMPString, T61String, or PrintableString. When encoding, it writes out the character string type that is actually passed in.

**d2i\_ASN1\_PRINTABLE**() and **i2d\_ASN1\_PRINTABLE**() are non-standard variants of **d2i\_DIRECTORYSTRING**() and **i2d\_DIRECTORYSTRING**() that also accept IA5String, NumericString, BIT STRING, and SEQUENCE ASN.1 values as well as ASN.1 values with unknown identifier bytes (0x07, 0x08, 0x09, 0x0b, 0x0d, 0x0e, 0x0f, 0x1d, and 0x1f). Even though the standard requires the use of *DirectoryString* in the relative distinguished names described in X509\_NAME\_ENTRY\_new(3), the library accepts this wider range of choices.

**d2i\_DISPLAYTEXT**() and **i2d\_DISPLAYTEXT**() decode and encode an ASN.1 *DisplayText* structure defined in RFC 5280 section 4.2.1.4 and used for ASN.1 *UserNotice* structures in certificate policies; see USERNOTICE\_new(3). When decoding, it accepts any of the types UTF8String, IA5String, BMPString, or VisibleString. When encoding, it writes out the character string type that is actually passed in.

**d2i\_ASN1\_TIME**() and **i2d\_ASN1\_TIME**() decode and encode an ASN.1 *Time* structure defined in RFC 5280 section 4.1 and used for ASN.1 *Validity* structures in certificates; see X509\_VAL\_new(3). They are also used for certificate revocation lists; see X509\_CRL\_INFO\_new(3). When decoding, it accepts either GeneralizedTime or UTCTime. When encoding, it writes out the time type that is actually passed in.

The following constants describe the ASN.1 tags that are valid when decoding with the above functions. See ASN1\_tag2bit(3) for more details about the B\_ASN1\_\* constants.

| | |
| --- | --- |
| decoding function | mask constant |
| **d2i\_DIRECTORYSTRING**() | B\_ASN1\_DIRECTORYSTRING |
| **d2i\_ASN1\_PRINTABLE**() | B\_ASN1\_PRINTABLE |
| **d2i\_DISPLAYTEXT**() | B\_ASN1\_DISPLAYTEXT |
| **d2i\_ASN1\_TIME**() | B\_ASN1\_TIME |

**d2i\_ASN1\_UINTEGER**() is similar to **d2i\_ASN1\_INTEGER**() except that it ignores the sign bit in the BER encoding and treats all integers as positive. It helps to process BER input produced by broken software that neglects adding a leading NUL content byte where required.

## RETURN VALUES

The **d2i\_\***() decoding functions return an *ASN1\_STRING* object or NULL if an error occurs.

The **i2d\_\***() encoding functions return the number of bytes successfully encoded or a negative value if an error occurs.

## SEE ALSO

ASN1\_item\_d2i(3), ASN1\_STRING\_new(3)

## STANDARDS

ITU-T Recommendation X.680, also known as ISO/IEC 8824-1: Information technology - Abstract Syntax Notation One (ASN.1): Specification of basic notation

RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile

## HISTORY

**d2i\_ASN1\_OCTET\_STRING**(), **i2d\_ASN1\_OCTET\_STRING**(), **d2i\_ASN1\_BIT\_STRING**(), **i2d\_ASN1\_BIT\_STRING**(), **d2i\_ASN1\_INTEGER**(), **i2d\_ASN1\_INTEGER**(), **d2i\_ASN1\_IA5STRING**(), **i2d\_ASN1\_IA5STRING**(), **d2i\_ASN1\_T61STRING**(), **i2d\_ASN1\_T61STRING**(), **d2i\_ASN1\_PRINTABLESTRING**(), **i2d\_ASN1\_PRINTABLESTRING**(), **d2i\_ASN1\_PRINTABLE**(), **i2d\_ASN1\_PRINTABLE**(), **d2i\_ASN1\_UTCTIME**(), and **i2d\_ASN1\_UTCTIME**() first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4.

**d2i\_ASN1\_BMPSTRING**() and **i2d\_ASN1\_BMPSTRING**() first appeared in SSLeay 0.9.1. **d2i\_ASN1\_ENUMERATED**(), **i2d\_ASN1\_ENUMERATED**(), **d2i\_ASN1\_GENERALIZEDTIME**(), **i2d\_ASN1\_GENERALIZEDTIME**(), **d2i\_ASN1\_TIME**(), and **i2d\_ASN1\_TIME**() first appeared in OpenSSL 0.9.2b. **d2i\_ASN1\_UINTEGER**(), **d2i\_ASN1\_UTF8STRING**(), **i2d\_ASN1\_UTF8STRING**(), **d2i\_ASN1\_VISIBLESTRING**(), **i2d\_ASN1\_VISIBLESTRING**(), **d2i\_DIRECTORYSTRING**(), **i2d\_DIRECTORYSTRING**(), **d2i\_DISPLAYTEXT**() and **i2d\_DISPLAYTEXT**() first appeared in OpenSSL 0.9.3. These functions have been available since OpenBSD 2.6.

**d2i\_ASN1\_UNIVERSALSTRING**(), **i2d\_ASN1\_UNIVERSALSTRING**(), **d2i\_ASN1\_GENERALSTRING**(), and **i2d\_ASN1\_GENERALSTRING**() first appeared in OpenSSL 0.9.7 and have been available since OpenBSD 3.2.

## CAVEATS

Other implementations may accept or emit invalid DER encodings of GeneralizedTime and UTCTime. Portable applications should use **ASN1\_STRING\_length**() to double check whether a given GeneralizedTime or UTCTime object is at least 15 or 13 bytes, respectively.
