D2I_GENERAL_NAME(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’… D2I_GENERAL_NAME β€” decode & encode names for X.509 extensions (libcrypto, bestie!)

okay so this whole page is about the little name-blobs that live inside X.509 extensions, and the functions that turn them from raw DER bytes into actual structs and back again. It's from the libcrypto library, and the header you need is:

#include <openssl/x509v3.h>

✨ SYNOPSIS ✨

GENERAL_NAME *
d2i_GENERAL_NAME(GENERAL_NAME **val_out, const unsigned char **der_in,
    long length);

int
i2d_GENERAL_NAME(GENERAL_NAME *val_in, unsigned char **der_out);

GENERAL_NAMES *
d2i_GENERAL_NAMES(GENERAL_NAMES **val_out, const unsigned char **der_in,
    long length);

int
i2d_GENERAL_NAMES(GENERAL_NAMES *val_in, unsigned char **der_out);

EDIPARTYNAME *
d2i_EDIPARTYNAME(EDIPARTYNAME **val_out, const unsigned char **der_in,
    long length);

int
i2d_EDIPARTYNAME(EDIPARTYNAME *val_in, unsigned char **der_out);

OTHERNAME *
d2i_OTHERNAME(OTHERNAME **val_out, const unsigned char **der_in,
    long length);

int
i2d_OTHERNAME(OTHERNAME *val_in, unsigned char **der_out);

🌸 DESCRIPTION 🌸

So these functions decode and encode names that you can use in X.509 extensions. That's the whole vibe. πŸ’–

For all the semantics, examples, caveats, and bugs β€” the juicy stuff β€” go read ASN1_item_d2i(3). That's where the lore lives, iykyk.

Here's the cast, one by one, each doing their little encode/decode thing:

  • d2i_GENERAL_NAME() and i2d_GENERAL_NAME() β€” decode and encode an ASN.1 GeneralName structure, defined in RFC 5280 section 4.2.1.6. ✨
  • d2i_GENERAL_NAMES() and i2d_GENERAL_NAMES() β€” decode and encode an ASN.1 GeneralNames structure, also RFC 5280 section 4.2.1.6. (yes it's plural, yes it's a different struct, no they're not the same thing bestie πŸ’…)
  • d2i_EDIPARTYNAME() and i2d_EDIPARTYNAME() β€” decode and encode an ASN.1 EDIPartyName structure, RFC 5280 section 4.2.1.6. iconic.
  • d2i_OTHERNAME() and i2d_OTHERNAME() β€” decode and encode an ASN.1 OtherName structure, RFC 5280 section 4.2.1.6. the catch-all main character 🫢

πŸŽ€ RETURN VALUES πŸŽ€

The d2i_* girlies β€” d2i_GENERAL_NAME(), d2i_GENERAL_NAMES(), d2i_EDIPARTYNAME(), and d2i_OTHERNAME() β€” return a GENERAL_NAME, GENERAL_NAMES, EDIPARTYNAME, or OTHERNAME object respectively (each one matches its own function, obviously πŸ’€), or NULL if something went wrong.

The i2d_* girlies β€” i2d_GENERAL_NAME(), i2d_GENERAL_NAMES(), i2d_EDIPARTYNAME(), and i2d_OTHERNAME() β€” return the number of bytes successfully encoded, or a negative value if an error occurs. That's it, that's the deal. 🌈


πŸ¦‹ SEE ALSO πŸ¦‹


πŸ‘‘ STANDARDS πŸ‘‘

RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile, section 4.2: Certificate Extensions. that's the source material, periodt. ⭐


πŸ’œ HISTORY πŸ’œ

the origin story, chronologically-ish:

  • d2i_GENERAL_NAME(), i2d_GENERAL_NAME(), d2i_GENERAL_NAMES(), and i2d_GENERAL_NAMES() first appeared in OpenSSL 0.9.2b and have been available since OpenBSD 2.6. πŸŽ€
  • d2i_OTHERNAME() and i2d_OTHERNAME() first appeared in OpenSSL 0.9.5 and have been available since OpenBSD 2.7. ✨
  • d2i_EDIPARTYNAME() and i2d_EDIPARTYNAME() first appeared in OpenSSL 0.9.7 and have been available since OpenBSD 3.2. πŸ¦‹

okay that's the whole page, go forth and encode responsibly. πŸ’…

this lil Debian edition is dated June 8, 2025 β€” mwah, sending u all the πŸ’– from the Debian crew, take care bestie!! 🫢

πŸ“¦ where this page comes from