1OBJ_NID2OBJ(3ossl)                  OpenSSL                 OBJ_NID2OBJ(3ossl)
2
3
4

NAME

6       i2t_ASN1_OBJECT, OBJ_length, OBJ_get0_data, OBJ_nid2obj, OBJ_nid2ln,
7       OBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid, OBJ_ln2nid, OBJ_sn2nid, OBJ_cmp,
8       OBJ_dup, OBJ_txt2obj, OBJ_obj2txt, OBJ_create, OBJ_cleanup,
9       OBJ_add_sigid - ASN1 object utility functions
10

SYNOPSIS

12        #include <openssl/objects.h>
13
14        ASN1_OBJECT *OBJ_nid2obj(int n);
15        const char *OBJ_nid2ln(int n);
16        const char *OBJ_nid2sn(int n);
17
18        int OBJ_obj2nid(const ASN1_OBJECT *o);
19        int OBJ_ln2nid(const char *ln);
20        int OBJ_sn2nid(const char *sn);
21
22        int OBJ_txt2nid(const char *s);
23
24        ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name);
25        int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
26
27        int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a);
28
29        int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);
30        ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o);
31
32        int OBJ_create(const char *oid, const char *sn, const char *ln);
33
34        size_t OBJ_length(const ASN1_OBJECT *obj);
35        const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj);
36
37        int OBJ_add_sigid(int signid, int dig_id, int pkey_id);
38
39       The following function has been deprecated since OpenSSL 1.1.0, and can
40       be hidden entirely by defining OPENSSL_API_COMPAT with a suitable
41       version value, see openssl_user_macros(7):
42
43        void OBJ_cleanup(void);
44

DESCRIPTION

46       The ASN1 object utility functions process ASN1_OBJECT structures which
47       are a representation of the ASN1 OBJECT IDENTIFIER (OID) type.  For
48       convenience, OIDs are usually represented in source code as numeric
49       identifiers, or NIDs.  OpenSSL has an internal table of OIDs that are
50       generated when the library is built, and their corresponding NIDs are
51       available as defined constants.  For the functions below, application
52       code should treat all returned values -- OIDs, NIDs, or names -- as
53       constants.
54
55       OBJ_nid2obj(), OBJ_nid2ln() and OBJ_nid2sn() convert the NID n to an
56       ASN1_OBJECT structure, its long name and its short name respectively,
57       or NULL if an error occurred.
58
59       OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() return the corresponding NID
60       for the object o, the long name ln or the short name sn respectively or
61       NID_undef if an error occurred.
62
63       OBJ_txt2nid() returns NID corresponding to text string s. s can be a
64       long name, a short name or the numerical representation of an object.
65
66       OBJ_txt2obj() converts the text string s into an ASN1_OBJECT structure.
67       If no_name is 0 then long names and short names will be interpreted as
68       well as numerical forms. If no_name is 1 only the numerical form is
69       acceptable.
70
71       OBJ_obj2txt() converts the ASN1_OBJECT a into a textual representation.
72       Unless buf is NULL, the representation is written as a NUL-terminated
73       string to buf, where at most buf_len bytes are written, truncating the
74       result if necessary.  In any case it returns the total string length,
75       excluding the NUL character, required for non-truncated representation,
76       or -1 on error.  If no_name is 0 then if the object has a long or short
77       name then that will be used, otherwise the numerical form will be used.
78       If no_name is 1 then the numerical form will always be used.
79
80       i2t_ASN1_OBJECT() is the same as OBJ_obj2txt() with the no_name set to
81       zero.
82
83       OBJ_cmp() compares a to b. If the two are identical 0 is returned.
84
85       OBJ_dup() returns a copy of o.
86
87       OBJ_create() adds a new object to the internal table. oid is the
88       numerical form of the object, sn the short name and ln the long name. A
89       new NID is returned for the created object in case of success and
90       NID_undef in case of failure.
91
92       OBJ_length() returns the size of the content octets of obj.
93
94       OBJ_get0_data() returns a pointer to the content octets of obj.  The
95       returned pointer is an internal pointer which must not be freed.
96
97       OBJ_add_sigid() creates a new composite "Signature Algorithm" that
98       associates a given NID with two other NIDs - one representing the
99       underlying signature algorithm and the other representing a digest
100       algorithm to be used in conjunction with it. signid represents the NID
101       for the composite "Signature Algorithm", dig_id is the NID for the
102       digest algorithm and pkey_id is the NID for the underlying signature
103       algorithm. As there are signature algorithms that do not require a
104       digest, NID_undef is a valid dig_id.
105
106       OBJ_cleanup() releases any resources allocated by creating new objects.
107

NOTES

109       Objects in OpenSSL can have a short name, a long name and a numerical
110       identifier (NID) associated with them. A standard set of objects is
111       represented in an internal table. The appropriate values are defined in
112       the header file objects.h.
113
114       For example the OID for commonName has the following definitions:
115
116        #define SN_commonName                   "CN"
117        #define LN_commonName                   "commonName"
118        #define NID_commonName                  13
119
120       New objects can be added by calling OBJ_create().
121
122       Table objects have certain advantages over other objects: for example
123       their NIDs can be used in a C language switch statement. They are also
124       static constant structures which are shared: that is there is only a
125       single constant structure for each table object.
126
127       Objects which are not in the table have the NID value NID_undef.
128
129       Objects do not need to be in the internal tables to be processed, the
130       functions OBJ_txt2obj() and OBJ_obj2txt() can process the numerical
131       form of an OID.
132
133       Some objects are used to represent algorithms which do not have a
134       corresponding ASN.1 OBJECT IDENTIFIER encoding (for example no OID
135       currently exists for a particular algorithm). As a result they cannot
136       be encoded or decoded as part of ASN.1 structures. Applications can
137       determine if there is a corresponding OBJECT IDENTIFIER by checking
138       OBJ_length() is not zero.
139
140       These functions cannot return const because an ASN1_OBJECT can
141       represent both an internal, constant, OID and a dynamically-created
142       one.  The latter cannot be constant because it needs to be freed after
143       use.
144

RETURN VALUES

146       OBJ_nid2obj() returns an ASN1_OBJECT structure or NULL is an error
147       occurred.
148
149       OBJ_nid2ln() and OBJ_nid2sn() returns a valid string or NULL on error.
150
151       OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() and OBJ_txt2nid() return a
152       NID or NID_undef on error.
153
154       OBJ_add_sigid() returns 1 on success or 0 on error.
155
156       i2t_ASN1_OBJECT() an OBJ_obj2txt() return -1 on error.  On success,
157       they return the length of the string written to buf if buf is not NULL
158       and buf_len is big enough, otherwise the total string length.  Note
159       that this does not count the trailing NUL character.
160

EXAMPLES

162       Create an object for commonName:
163
164        ASN1_OBJECT *o = OBJ_nid2obj(NID_commonName);
165
166       Check if an object is commonName
167
168        if (OBJ_obj2nid(obj) == NID_commonName)
169            /* Do something */
170
171       Create a new NID and initialize an object from it:
172
173        int new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
174        ASN1_OBJECT *obj = OBJ_nid2obj(new_nid);
175
176       Create a new object directly:
177
178        obj = OBJ_txt2obj("1.2.3.4", 1);
179

BUGS

181       Neither OBJ_create() nor OBJ_add_sigid() do any locking and are thus
182       not thread safe.  Moreover, none of the other functions should be
183       called while concurrent calls to these two functions are possible.
184

SEE ALSO

186       ERR_get_error(3)
187

HISTORY

189       OBJ_cleanup() was deprecated in OpenSSL 1.1.0 by OPENSSL_init_crypto(3)
190       and should not be used.
191
193       Copyright 2002-2021 The OpenSSL Project Authors. All Rights Reserved.
194
195       Licensed under the Apache License 2.0 (the "License").  You may not use
196       this file except in compliance with the License.  You can obtain a copy
197       in the file LICENSE in the source distribution or at
198       <https://www.openssl.org/source/license.html>.
199
200
201
2023.0.5                             2022-07-05                OBJ_NID2OBJ(3ossl)
Impressum