D2I_ASN1_OCTET_STRING(3)
π D2I_ASN1_OCTET_STRING(3) β Library Functions Manual β¨
okay so bestie, this is a page from the Library Functions Manual and it's literally about decoding and encoding ASN1_STRING objects. yes it's a whole family. yes there are like a million of them. buckle up π
πΈ NAME πΈ
The whole girl gang of decode/encode pairs, and their job is: decode and encode ASN1_STRING objects. periodt.
d2i_ASN1_OCTET_STRING,i2d_ASN1_OCTET_STRINGd2i_ASN1_BIT_STRING,i2d_ASN1_BIT_STRINGd2i_ASN1_INTEGER,i2d_ASN1_INTEGERd2i_ASN1_UINTEGERd2i_ASN1_ENUMERATED,i2d_ASN1_ENUMERATEDd2i_ASN1_UTF8STRING,i2d_ASN1_UTF8STRINGd2i_ASN1_IA5STRING,i2d_ASN1_IA5STRINGd2i_ASN1_UNIVERSALSTRING,i2d_ASN1_UNIVERSALSTRINGd2i_ASN1_BMPSTRING,i2d_ASN1_BMPSTRINGd2i_ASN1_GENERALSTRING,i2d_ASN1_GENERALSTRINGd2i_ASN1_T61STRING,i2d_ASN1_T61STRINGd2i_ASN1_VISIBLESTRING,i2d_ASN1_VISIBLESTRINGd2i_ASN1_PRINTABLESTRING,i2d_ASN1_PRINTABLESTRINGd2i_ASN1_PRINTABLE,i2d_ASN1_PRINTABLEd2i_DIRECTORYSTRING,i2d_DIRECTORYSTRINGd2i_DISPLAYTEXT,i2d_DISPLAYTEXTd2i_ASN1_GENERALIZEDTIME,i2d_ASN1_GENERALIZEDTIMEd2i_ASN1_UTCTIME,i2d_ASN1_UTCTIMEd2i_ASN1_TIME,i2d_ASN1_TIME
π¦ SYNOPSIS π¦
library "libcrypto" #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 π
So these functions decode and encode a whole bunch of ASN.1 built-in types β the ones that can be represented by ASN1_STRING objects. For the details about the semantics, examples, caveats, and bugs, go look at ASN1_item_d2i(3), bestie, they put all of that over there.
The format is literally: one identifier byte, then one or more length bytes, then one or more content bytes. iconic. The identifier bytes and their matching ASN.1 types go like this π
ASN1_OCTET_STRINGβ identifier0x04β ASN.1 typeOCTET STRINGASN1_BIT_STRINGβ identifier0x03β ASN.1 typeBIT STRINGASN1_INTEGERβ identifier0x02β ASN.1 typeINTEGERASN1_ENUMERATEDβ identifier0x0aβ ASN.1 typeENUMERATEDASN1_UTF8STRINGβ identifier0x0cβ ASN.1 typeUTF8StringASN1_IA5STRINGβ identifier0x16β ASN.1 typeIA5StringASN1_UNIVERSALSTRINGβ identifier0x1cβ ASN.1 typeUniversalStringASN1_BMPSTRINGβ identifier0x1eβ ASN.1 typeBMPStringASN1_GENERALSTRINGβ identifier0x1bβ ASN.1 typeGeneralStringASN1_T61STRINGβ identifier0x14β ASN.1 typeT61StringASN1_VISIBLESTRINGβ identifier0x1aβ ASN.1 typeVisibleStringASN1_PRINTABLESTRINGβ identifier0x13β ASN.1 typePrintableStringASN1_GENERALIZEDTIMEβ identifier0x18β ASN.1 typeGeneralizedTimeASN1_UTCTIMEβ identifier0x17β ASN.1 typeUTCTime
d2i_DIRECTORYSTRING() and i2d_DIRECTORYSTRING() decode and encode an ASN.1 DirectoryString structure β it's defined in RFC 5280 section 4.1.2.4 and it's used for ASN.1 EDIPartyName structures; peep EDIPARTYNAME_new(3). When it's decoding, it accepts any of the types UTF8String, UniversalString, BMPString, T61String, or PrintableString. When it's encoding, it writes out the character string type that is actually passed in. no cap.
d2i_ASN1_PRINTABLE() and i2d_ASN1_PRINTABLE() are the non-standard variants of d2i_DIRECTORYSTRING() and i2d_DIRECTORYSTRING() β they also accept IA5String, NumericString, BIT STRING, and SEQUENCE ASN.1 values, plus ASN.1 values with unknown identifier bytes (0x07, 0x08, 0x09, 0x0b, 0x0d, 0x0e, 0x0f, 0x1d, and 0x1f). And likeβ¦ 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. it's giving lenient π
d2i_DISPLAYTEXT() and i2d_DISPLAYTEXT() decode and encode an ASN.1 DisplayText structure β defined in RFC 5280 section 4.2.1.4, 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, used for ASN.1 Validity structures in certificates; see X509_VAL_new(3). They're 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. π«Ά
d2i_DIRECTORYSTRING()β mask constantB_ASN1_DIRECTORYSTRINGd2i_ASN1_PRINTABLE()β mask constantB_ASN1_PRINTABLEd2i_DISPLAYTEXT()β mask constantB_ASN1_DISPLAYTEXTd2i_ASN1_TIME()β mask constantB_ASN1_TIME
d2i_ASN1_UINTEGER() is basically d2i_ASN1_INTEGER()'s sibling, except it ignores the sign bit in the BER encoding and treats all integers as positive. It's the designated helper for processing BER input produced by broken software that neglects adding a leading NUL content byte where required. likeβ¦ someone didn't do their homework and this function is doing damage control π
β RETURN VALUES β
- The
d2i_*()decoding functions return anASN1_STRINGobject, orNULLif 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. ancestors fr fr π§
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 ofGeneralizedTimeandUTCTime. π Portable applications should useASN1_STRING_length()to double check whether a givenGeneralizedTimeorUTCTimeobject is at least 15 or 13 bytes, respectively. don't skip the vibe check on your lengths, bestie.
and that's the whole page, bestie β you ate that π β¨
<tulip>this masterpiece is brought to you by Debian, dated June 8, 2025, filed under D2I_ASN1_OCTET_STRING(3) β slay, drink water, and always check your lengths ππ</tulip>
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms