ASN1_OBJECT_NEW(3)

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

✨ ASN1_OBJECT_NEW(3) ✨

okay so bestie, this is a page from the libcrypto Library Functions Manual and we're talking about ASN.1 object identifiers today. stay with me, it's actually so good πŸ’…


πŸŽ€ NAME πŸŽ€

ASN1_OBJECT_new, ASN1_OBJECT_create, ASN1_OBJECT_free β€” literally the ASN.1 object identifier girlies πŸ¦‹


🌸 SYNOPSIS 🌸

#include <openssl/asn1.h>

ASN1_OBJECT *
ASN1_OBJECT_new(void);

ASN1_OBJECT *
ASN1_OBJECT_create(int nid, unsigned char *content, int len,
    const char *short_name, const char *long_name);

void
ASN1_OBJECT_free(ASN1_OBJECT *a);

this whole thing lives in the libcrypto library, just so you know πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

🫢 ASN1_OBJECT_new()

bestie, ASN1_OBJECT_new() allocates and initializes an empty ASN1_OBJECT object β€” and that thing is representing an ASN.1 OBJECT IDENTIFIER. it's giving blank canvas energy ✨

so what can it even hold? a whole little squad of stuff:

  • a short name
  • a long name
  • a numeric identifier (aka a NID)
  • a sequence of integers that identifies a node in the International Object Identifier tree, as specified in ITU-T recommendation X.660 🌳

and the new object? marked as dynamically allocated. periodt.

also like, the ASN.1 object identifier type is also represented by the V_ASN1_OBJECT type identifier constant. two names, one icon πŸ‘‘

🧚 ASN1_OBJECT_create()

this one allocates a new ASN1_OBJECT with the given nid, copies the len DER content octets, the short_name, and the long_name into it, and then marks the new object and all data contained in it as dynamically allocated. it's a full package deal, no cap πŸ’…

ngl, real talk: application programs normally use utility functions like OBJ_nid2obj(3) rather than using ASN1_OBJECT_new() or ASN1_OBJECT_create() directly. iykyk.

πŸ’€ ASN1_OBJECT_free()

okay so this one has a few effects, and you gotta know all of them:

  • all data contained in a that is marked as dynamically allocated gets freed, and the respective fields of a become empty. anything contained that is not marked as dynamically allocated stays intact, untouched, living its truth 🌈
  • if the object a itself is marked as dynamically allocated, it is freed. otherwise, the pointer a remains valid β€” it survives, main character energy πŸ‘‘
  • if a is a NULL pointer, or if neither the object itself nor any of its content is marked as dynamically allocated, then nothing happens. no action, no drama πŸ™ˆ

⭐ RETURN VALUES ⭐

ASN1_OBJECT_new() and ASN1_OBJECT_create() return a pointer to the new object β€” or NULL if memory allocation fails (😭 rude but okay).


πŸ”₯ ERRORS πŸ”₯

after a failure of ASN1_OBJECT_new() or ASN1_OBJECT_create(), you can pull the following diagnostic with ERR_get_error(3), ERR_GET_REASON(3), and ERR_reason_error_string(3):

  • ERR_R_MALLOC_FAILURE "malloc failure" β€” memory allocation failed. that's it, that's the whole vibe πŸ’€

and after some cases of failure of ASN1_OBJECT_create(), you can retrieve this one in addition to the above:

  • ERR_R_ASN1_LIB "ASN1 lib" β€” memory allocation failed. (yes bestie, same description, that's not a typo on my end 🫢)

πŸ¦‹ SEE ALSO πŸ¦‹

a2d_ASN1_OBJECT(3), ASN1_TYPE_get(3), d2i_ASN1_OBJECT(3), OBJ_create(3), OBJ_nid2obj(3)

the whole friend group, go read them πŸ’œ


🌸 STANDARDS 🌸

  • ITU-T Recommendation X.208, also known as ISO/IEC 8824-1: Specification of Abstract Syntax Notation One (ASN.1), section 28: Notation for the object identifier type
  • ITU-T Recommendation X.690, also known as ISO/IEC 8825-1: Information technology - ASN.1 encoding rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER), section 8.19: Encoding of an object identifier value

standards queen behavior, honestly πŸ‘‘


πŸŽ€ HISTORY πŸŽ€

ASN1_OBJECT_new() and ASN1_OBJECT_free() first appeared in SSLeay 0.5.1, and ASN1_OBJECT_create() showed up in SSLeay 0.8.0. these functions have been available since OpenBSD 2.4. literal elders, we respect them 🫑


πŸ’€ BUGS πŸ’€

okay so this is the messy part, listen up πŸ™ˆ

the function ASN1_OBJECT_new() is not useful for any practical purpose because the library does not provide any function capable of adding data to an existing object. so if your application program creates an object with ASN1_OBJECT_new(), that object will always remain empty. forever. an empty vibe. 😭

similarly, if an nid of NID_undef is passed to ASN1_OBJECT_create(), or if NULL is passed for any of its pointer arguments, the returned object will permanently remain incomplete. permanently. incomplete. don't do it bestie πŸ’…


and that's the page! πŸŽ€ this one came from Debian, dated June 8, 2025 β€” mwah, thanks for reading, love u, bye 🫢✨

πŸ“¦ where this page comes from