ASN1_ITEM_PACK(3)
π 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, orNULLif memory allocation or encoding fails. πASN1_item_unpack()β returns the new object, orNULLif 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
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2021 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