NAME
OBJ_new_nid, OBJ_create, OBJ_create_objects, OBJ_cleanup – modify the table of ASN.1 object identifiers
SYNOPSIS
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);
DESCRIPTION
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);
SEE ALSO
ASN1_OBJECT_new(3), OBJ_nid2obj(3)
HISTORY
OBJ_new_nid(), and OBJ_cleanup() first appeared in SSLeay 0.8.0 and OBJ_create() in SSLeay 0.9.0. These functions have been available since OpenBSD 2.4.
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.
BUGS
OBJ_new_nid() does not reserve any return value to indicate an error. Consequently, to avoid conflicting NID assignments and integer overflows, care must be taken to not pass negative, zero, or large arguments to OBJ_new_nid().
OBJ_create_objects() does not distinguish between end of file, I/O errors, temporary unavailability of data on a non-blocking BIO, invalid input syntax, and memory allocation failure. In all these cases, reading is aborted and the number of objects that were already added is returned.