ASN1_ITEM_PACK(3)

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

πŸ’œ ASN1_ITEM_PACK(3) β€” the libcrypto glow-up for your ASN.1 objects

okay so this page lives in section 3 of the manual, bestie β€” it's ASN1_ITEM_PACK(3), a Library Functions Manual situation, and it's all about squishing an ASN.1 object into an ASN1_STRING and then getting it back out again. two little functions, one very important job. let's go ✨


🌸 NAME 🌸

ASN1_item_pack, ASN1_item_unpack β€” pack an ASN.1 object into an ASN1_STRING

like, that's literally the whole thing. pack it up, unpack it back. iconic behavior honestly πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

the library is β€œlibcrypto” and you're gonna want this include, no cap:

#include <openssl/asn1.h>

here are the two function signatures, exactly, character for character, because we do not mess with the code πŸ’…

ASN1_STRING *
ASN1_item_pack(void *val_in, const ASN1_ITEM *it,
    ASN1_STRING **string_out);

void *
ASN1_item_unpack(const ASN1_STRING *string_in, const ASN1_ITEM *it);

🧚 DESCRIPTION 🧚

πŸ“ ASN1_item_pack()

so ASN1_item_pack() takes the object that val_in points to and encodes it into DER format β€” it does that using ASN1_item_i2d(3), which is doing the actual heavy lifting behind the scenes β€” and then it stores the encoded form in **string_out. ✨

and here's the cute part: if string_out or *string_out is a NULL pointer, a brand-new ASN1_STRING object gets allocated and returned to you. main character energy β€” it makes its own container. 🫢

🌈 ASN1_item_unpack()

meanwhile ASN1_item_unpack() looks at the data inside string_in, treats it as a DER- or BER-encoded byte array, and decodes one value of the type into a freshly allocated object using ASN1_item_d2i(3). new object, who dis 😭

notice the vibe check here: packing always produces DER, but unpacking is chill and accepts either DER or BER. iykyk.


πŸ‘‘ RETURN VALUES πŸ‘‘

  • ASN1_item_pack() β€” returns the modified or new object, or NULL if memory allocation or encoding fails. πŸ’€
  • ASN1_item_unpack() β€” returns the new object, or NULL if memory allocation or decoding fails. πŸ™ˆ

so like... if you get NULL back, something went wrong. don't ignore it, bestie.


πŸ’– SEE ALSO πŸ’–

go read these next, they're the friend group:


⭐ HISTORY ⭐

ASN1_item_pack() and ASN1_item_unpack() first appeared in OpenSSL 0.9.7 and have been available since OpenBSD 3.2. og functions fr fr πŸ§šβ€β™€οΈ


πŸŽ€ BUGS πŸŽ€

not me having to point you at another page for the drama 😭 β€” see the BUGS section in ASN1_item_i2d(3). that's where the tea is.

and that's the whole page, bestie β€” slay, you now understand ASN1_item_pack(3) πŸ¦‹πŸ’…

this one's from the Debian build, dated June 8, 2025 β€” mwah, catch you in the next manpage πŸ’œβœ¨

πŸ“¦ where this page comes from