1OBJ_NID2OBJ(3)                      OpenSSL                     OBJ_NID2OBJ(3)
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 - ASN1
9       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       Deprecated:
38
39        #if OPENSSL_API_COMPAT < 0x10100000L
40        void OBJ_cleanup(void)
41        #endif
42

DESCRIPTION

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

NOTES

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

RETURN VALUES

135       OBJ_nid2obj() returns an ASN1_OBJECT structure or NULL is an error
136       occurred.
137
138       OBJ_nid2ln() and OBJ_nid2sn() returns a valid string or NULL on error.
139
140       OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() and OBJ_txt2nid() return a
141       NID or NID_undef on error.
142
143       OBJ_add_sigid() returns 1 on success or 0 on error.
144
145       i2t_ASN1_OBJECT() an OBJ_obj2txt() return -1 on error.  On success,
146       they return the length of the string written to buf if buf is not NULL
147       and buf_len is big enough, otherwise the total string length.  Note
148       that this does not count the trailing NUL character.
149

EXAMPLES

151       Create an object for commonName:
152
153        ASN1_OBJECT *o = OBJ_nid2obj(NID_commonName);
154
155       Check if an object is commonName
156
157        if (OBJ_obj2nid(obj) == NID_commonName)
158            /* Do something */
159
160       Create a new NID and initialize an object from it:
161
162        int new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
163        ASN1_OBJECT *obj = OBJ_nid2obj(new_nid);
164
165       Create a new object directly:
166
167        obj = OBJ_txt2obj("1.2.3.4", 1);
168

SEE ALSO

170       ERR_get_error(3)
171

HISTORY

173       OBJ_cleanup() was deprecated in OpenSSL 1.1.0 by OPENSSL_init_crypto(3)
174       and should not be used.
175
177       Copyright 2002-2022 The OpenSSL Project Authors. All Rights Reserved.
178
179       Licensed under the OpenSSL license (the "License").  You may not use
180       this file except in compliance with the License.  You can obtain a copy
181       in the file LICENSE in the source distribution or at
182       <https://www.openssl.org/source/license.html>.
183
184
185
1861.1.1q                            2022-07-21                    OBJ_NID2OBJ(3)
Impressum