libressl-OBJ_create3
Modify the table of asn.1 object identifiers
Usage
Crypto Library (libcrypto, -lcrypto)
#include <openssl/objects.h>
int
OBJ_new_nid(int increment);
int
OBJ_create(const char *oid, const char *sn, const char *ln);
int
OBJ_create_objects(BIO *in_bio);
void
OBJ_cleanup(void);
Overview
OBJ_new_nid() returns the smallest currently unassigned ASN.1 numeric object identifier (NID) and reserves increment consecutive NIDs starting with it. Passing an argument of 1 is usually recommended. The return value can be assigned to a new object by passing it as the nid argument to ASN1_OBJECT_create(3).
OBJ_create() adds an ASN1_OBJECT to the internal table of ASN.1 object identifiers for use by OBJ_nid2obj(3) and related functions. oid is the numerical form of the object, sn the short name and ln the long name. A new NID is automatically assigned using OBJ_new_nid().
OBJ_create_objects() reads text lines of the form
oid, sn, ln
from in_bio and calls OBJ_create(oid, sn, ln) for every line read. The three fields of the input lines are separated by one or more whitespace characters.
For the objects added to the internal table by OBJ_create() and OBJ_create_objects(), all the data contained is marked as not dynamically allocated. Consequently, retrieving them with OBJ_nid2obj(3) or a similar function and then calling ASN1_OBJECT_free(3) on the returned pointer will have no effect.
OBJ_cleanup() resets the internal object table to its default state, removing and freeing all objects that were added with OBJ_create(), or OBJ_create_objects().
Return values
OBJ_new_nid() returns the new NID.
OBJ_create() returns the new NID or NID_undef if oid is not a valid representation of an object identifier or if memory allocation fails.
OBJ_create_objects() returns the number of objects added.
In some cases of failure of OBJ_create() and OBJ_create_objects(), the reason can be determined with ERR_get_error(3).
Examples
Create a new NID and initialize an object from it:
int new_nid;
ASN1_OBJECT *obj;
new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
obj = OBJ_nid2obj(new_nid);
Caveats
OBJ_create() tolerates NULL pointers being passed for the sn and/or ln arguments, in which case OBJ_nid2sn(3) and OBJ_sn2nid(3) and/or OBJ_nid2ln(3) and OBJ_ln2nid(3) will not work on the added object.