ASN1_ITEM_NEW(3)
πΈ NAME πΈ
okay so this is the ASN1_ITEM_NEW(3) page from the Library Functions Manual, and itβs giving generic ASN.1 value constructor and destructor energy β the main characters are ASN1_item_new and ASN1_item_free, and they are literally the constructor/destructor duo for generic ASN.1 values. π
β¨ SYNOPSIS β¨
bestie, youβre linking the library βlibcryptoβ β hereβs the include and the exact signatures, no cap:
#include <openssl/asn1.h>
ASN1_VALUE *
ASN1_item_new(const ASN1_ITEM *it);
void
ASN1_item_free(ASN1_VALUE *val_in, const ASN1_ITEM *it);
π DESCRIPTION π
ASN1_item_new() allocates and initializes an empty ASN.1 value of the type described by the global static object it. thatβs the whole main-character move here. β¨
If the item type described by it is reference counted, ASN1_item_free() decrements the reference count of val_in. Otherwise β or if the reference count reaches 0 β ASN1_item_free() frees val_in, assuming that it is of the type described by it. π«Ά
β οΈ okay but for real: if the true type ofval_infails to match the specifiedit, buffer overflows and segmentation faults are likely to occur. It is not possible to recover the type of anASN1_VALUEobject by inspecting it; the type always needs to be remembered separately. so keep that type info safe, bestie π
ASN1_VALUE is an incomplete type, and pointers to it always require casting to the correct complete type before they can be dereferenced. For all practical purposes, a pointer to ASN1_VALUE is equivalent to a void pointer. iykyk. π¦
Depending on it, there are more than 150 different types that ASN1_item_new() may return. Most of them are pointers to structures or pointers to arrays of structures, but there are a few exceptions, for example:
- If
itisASN1_NULL_it,ASN1_item_new()returns a specific invalid pointer representing the uniqueASN1_NULLobject. - If
itisLONG_it,ASN1_item_new()does not return a pointer at all, but alongvalue cast toASN1_VALUE *.
π«Ά RETURN VALUES π«Ά
The ASN1_item_new() function returns the new ASN1_VALUE object if successful; otherwise NULL is returned and an error code can be retrieved with ERR_get_error(3). slay when it works, check that error when it doesnβt. π
π₯ SEE ALSO π₯
ASN1_get_object(3)ASN1_item_d2i(3)ASN1_item_digest(3)ASN1_item_pack(3)ASN1_item_sign(3)ASN1_item_verify(3)ASN1_NULL_new(3)ASN1_TYPE_new(3)d2i_ASN1_NULL(3)OBJ_nid2obj(3)
π¦ HISTORY π¦
ASN1_item_new() and ASN1_item_free() first appeared in OpenSSL 0.9.7 and have been available since OpenBSD 3.2. vintage but still iconic, fr fr. π
π BUGS π
The ASN1_VALUE type compromises type safety and invites programming mistakes that will typically have severe consequences. not me calling out the whole type system, but itβs true ππ
mwah π this has been the Debian source/version, dated June 8, 2025, for the ASN1_ITEM_NEW(3) manual page β bye bestie, go cast your pointers correctly π«Άπ
π¦ 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) 2016, 2018 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