Scroll to navigation

OBJ_CREATE(3) Library Functions Manual OBJ_CREATE(3)

NAME

OBJ_new_nid, OBJ_add_object, OBJ_create, OBJ_create_objects, OBJ_cleanupmodify the table of ASN.1 object identifiers

SYNOPSIS

#include <openssl/objects.h>

int
OBJ_new_nid(int increment);

int
OBJ_add_object(const ASN1_OBJECT *object);

int
OBJ_create(const char *oid, const char *sn, const char *ln);

int
OBJ_create_objects(BIO *in_bio);

void
OBJ_cleanup(void);

DESCRIPTION

() 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) and by passing the resulting object to OBJ_add_object().

() adds a copy of the object to the internal table of ASN.1 object identifiers for use by OBJ_nid2obj(3) and related functions.

() provides a simpler way to add a new object to the internal table. 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().

() reads text lines of the form

oid sn ln

from in_bio and calls (oid, sn, ln) for every line read. The three fields of the input lines are separated by one or more whitespace characters.

For all three functions, the objects added to the internal table and all the data contained in them 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.

() resets the internal object table to its default state, removing and freeing all objects that were added with OBJ_add_object(), OBJ_create(), or OBJ_create_objects().

RETURN VALUES

OBJ_new_nid() returns the new NID.

OBJ_add_object() returns the NID of the added object or NID_undef if no object was added because the object argument was NULL, did not contain an NID, or memory allocation failed.

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_add_object(), 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(), OBJ_add_object(), 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_add_object() indicates success even after adding an incomplete object that was created with ASN1_OBJECT_create(3) but lacks a short name, a long name, or an OID.

Even OBJ_create() tolerates NULL pointers being passed for the sn and/or ln arguments, in which case OBJ_nid2sn(3) and OBJ_sn2nid(3) or OBJ_nid2ln(3) and OBJ_ln2nid(3) will not work on the added object, respectively.

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.

January 31, 2024 Linux 6.4.0-150600.23.25-default