OBJ_NID2OBJ(3SSL)
β¨ NAME β¨
okay bestie, gather round, because this page is the whole ASN1 object friend group: i2t_ASN1_OBJECT, OBJ_length, OBJ_get0_data, OBJ_nid2obj, OBJ_nid2ln, OBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid, OBJ_ln2nid, OBJ_sn2nid, OBJ_cmp, OBJ_dup, OBJ_txt2obj, OBJ_obj2txt, OBJ_create, OBJ_cleanup, OBJ_add_sigid β aka the ASN1 object utility functions. π
πΈ SYNOPSIS πΈ
first thing, you gotta invite the header file in:
#include <openssl/objects.h>
then the squad rolls up like this:
ASN1_OBJECT *OBJ_nid2obj(int n);
const char *OBJ_nid2ln(int n);
const char *OBJ_nid2sn(int n);
int OBJ_obj2nid(const ASN1_OBJECT *o);
int OBJ_ln2nid(const char *ln);
int OBJ_sn2nid(const char *sn);
int OBJ_txt2nid(const char *s);
ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name);
int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a);
int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);
ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o);
int OBJ_create(const char *oid, const char *sn, const char *ln);
size_t OBJ_length(const ASN1_OBJECT *obj);
const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj);
int OBJ_add_sigid(int signid, int dig_id, int pkey_id);
and now the one that's lowkey cancelled π this next function has been deprecated since OpenSSL 1.1.0, and you can hide it entirely by defining OPENSSL_API_COMPAT with a suitable version value β see openssl_user_macros(7):
void OBJ_cleanup(void);
π DESCRIPTION π
so the ASN1 object utility functions are the ones that handle ASN1_OBJECT structures, which are basically the glow-up of the ASN1 OBJECT IDENTIFIER (OID) type. For convenience, OIDs usually show up in source code as numeric identifiers, aka NIDs. OpenSSL keeps an internal table of OIDs that gets generated when the library is built, and their matching NIDs are sitting right there as defined constants. For all the functions below, application code should treat every returned value β OIDs, NIDs or names β as constants. no take-backs, no editing. π«Ά
OBJ_nid2obj(),OBJ_nid2ln()andOBJ_nid2sn()β these three take the NIDnand convert it into anASN1_OBJECTstructure, its long name, and its short name respectively. If something went wrong, you getNULL. πOBJ_obj2nid(),OBJ_ln2nid(),OBJ_sn2nid()β the reverse trip: they return the matching NID for the objecto, the long nameln, or the short namesnrespectively, orNID_undefif an error happened.OBJ_txt2nid()β returns the NID that corresponds to the text strings. andsis flexible bestie, it can be a long name, a short name, or the numerical representation of an object. β¨OBJ_txt2obj()β converts the text stringsinto anASN1_OBJECTstructure. Ifno_nameis0, then long names and short names get interpreted as well as the numerical forms. Ifno_nameis1, only the numerical form is acceptable. periodt.OBJ_obj2txt()β converts theASN1_OBJECTainto a textual representation. UnlessbufisNULL, that representation gets written as a NUL-terminated string tobuf, where at mostbuf_lenbytes are written, truncating the result if necessary. Either way it returns the total string length, excluding the NUL character, that's required for the non-truncated representation β or-1on error. Ifno_nameis0, then if the object has a long or short name that one gets used, otherwise the numerical form is used. Ifno_nameis1, the numerical form is always used. no exceptions, she's committed. πi2t_ASN1_OBJECT()β literally justOBJ_obj2txt()withno_nameset to zero. same energy, less typing.OBJ_cmp()β comparesatob. If the two are identical,0is returned. πOBJ_dup()β hands you a copy ofo. iconic behaviour.OBJ_create()β adds a new object to the internal table.oidis the numerical form of the object,snis the short name andlnis the long name. On success you get a new NID for the created object back; on failure you getNID_undef. Any ofoid,snandlnmay beNULL, but not all at once β pick at least one, bestie, we're not doing that today. πOBJ_length()β returns the size of the content octets ofobj.OBJ_get0_data()β returns a pointer to the content octets ofobj. careful though: the returned pointer is an internal pointer which must not be freed. do NOT free it. I'm serious. π¨OBJ_add_sigid()β creates a new composite "Signature Algorithm" that associates a given NID with two other NIDs: one representing the underlying signature algorithm, and the other representing a digest algorithm to be used in conjunction with it.signidis the NID for the composite "Signature Algorithm",dig_idis the NID for the digest algorithm, andpkey_idis the NID for the underlying signature algorithm. And because some signature algorithms don't need a digest at all,NID_undefis a totally validdig_id. slay. πOBJ_cleanup()β releases any resources allocated by creating new objects.
π NOTES π
Objects in OpenSSL can have a short name, a long name and a numerical identifier (NID) attached to them. A standard set of objects lives in an internal table, and the appropriate values are defined in the header file objects.h. π
for example, the OID for commonName has these definitions:
#define SN_commonName "CN"
#define LN_commonName "commonName"
#define NID_commonName 13
New objects can be added by calling OBJ_create(). β¨
Table objects have certain advantages over other objects: their NIDs can be used in a C language switch statement, for example. They're also static constant structures which are shared β meaning there is only a single constant structure for each table object. main character energy, honestly. π
Objects which are not in the table have the NID value NID_undef. π¬
Good news: objects do not need to be in the internal tables to be processed β OBJ_txt2obj() and OBJ_obj2txt() can handle the numerical form of an OID all on their own. πͺ
Some objects are used to represent algorithms which don't have a corresponding ASN.1 OBJECT IDENTIFIER encoding (for example, no OID currently exists for a particular algorithm). Because of that, they can't be encoded or decoded as part of ASN.1 structures. Applications can figure out whether there's a corresponding OBJECT IDENTIFIER by checking that OBJ_length() is not zero. π
These functions cannot return const because an ASN1_OBJECT can represent both an internal, constant, OID and a dynamically-created one. The latter can't be constant because it needs to be freed after use. the duality of OID. π¦
β οΈ heads up: these functions were not thread safe in OpenSSL 3.0 and before. fr fr, keep that in mind.
π¦ RETURN VALUES π¦
OBJ_nid2obj()β returns anASN1_OBJECTstructure, orNULLif an error occurred.OBJ_nid2ln()andOBJ_nid2sn()β return a valid string, orNULLon error.OBJ_obj2nid(),OBJ_ln2nid(),OBJ_sn2nid()andOBJ_txt2nid()β return a NID, orNID_undefon error.OBJ_add_sigid()β returns1on success or0on error.i2t_ASN1_OBJECT()andOBJ_obj2txt()β return-1on error. On success, they return the length of the string written tobufifbufis notNULLandbuf_lenis big enough, otherwise the total string length. and note: this does not count the trailing NUL character. no cap. π
β EXAMPLES β
Create an object for commonName:
ASN1_OBJECT *o = OBJ_nid2obj(NID_commonName);
Check if an object is commonName:
if (OBJ_obj2nid(obj) == NID_commonName)
/* Do something */
Create a new NID and initialize an object from it:
int new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
ASN1_OBJECT *obj = OBJ_nid2obj(new_nid);
Create a new object directly:
obj = OBJ_txt2obj("1.2.3.4", 1);
π SEE ALSO π
go read ERR_get_error(3) next, bestie. it's giving required reading. π«Ά
π HISTORY π
OBJ_cleanup() was deprecated in OpenSSL 1.1.0 by OPENSSL_init_crypto(3) and should not be used. she's retired, let her rest. π
π COPYRIGHT π
Copyright 2002-2021 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page, babe π this was OpenSSL 4.0.3, dated 2026-09-29, filed under OBJ_NID2OBJ(3SSL). ily, go convert some OIDs. πβ¨π¦
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms