1OBJ_NID2OBJ(3) OpenSSL OBJ_NID2OBJ(3)
2
3
4
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
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
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 The representation is written as a null terminated string to buf at
71 most buf_len bytes are written, truncating the result if necessary.
72 The total amount of space required is returned. If no_name is 0 then if
73 the object has a long or short name then that will be used, otherwise
74 the numerical form will be used. If no_name is 1 then the numerical
75 form will always be used.
76
77 i2t_ASN1_OBJECT() is the same as OBJ_obj2txt() with the no_name set to
78 zero.
79
80 OBJ_cmp() compares a to b. If the two are identical 0 is returned.
81
82 OBJ_dup() returns a copy of o.
83
84 OBJ_create() adds a new object to the internal table. oid is the
85 numerical form of the object, sn the short name and ln the long name. A
86 new NID is returned for the created object in case of success and
87 NID_undef in case of failure.
88
89 OBJ_length() returns the size of the content octets of obj.
90
91 OBJ_get0_data() returns a pointer to the content octets of obj. The
92 returned pointer is an internal pointer which must not be freed.
93
94 OBJ_cleanup() releases any resources allocated by creating new objects.
95
97 Objects in OpenSSL can have a short name, a long name and a numerical
98 identifier (NID) associated with them. A standard set of objects is
99 represented in an internal table. The appropriate values are defined in
100 the header file objects.h.
101
102 For example the OID for commonName has the following definitions:
103
104 #define SN_commonName "CN"
105 #define LN_commonName "commonName"
106 #define NID_commonName 13
107
108 New objects can be added by calling OBJ_create().
109
110 Table objects have certain advantages over other objects: for example
111 their NIDs can be used in a C language switch statement. They are also
112 static constant structures which are shared: that is there is only a
113 single constant structure for each table object.
114
115 Objects which are not in the table have the NID value NID_undef.
116
117 Objects do not need to be in the internal tables to be processed, the
118 functions OBJ_txt2obj() and OBJ_obj2txt() can process the numerical
119 form of an OID.
120
121 Some objects are used to represent algorithms which do not have a
122 corresponding ASN.1 OBJECT IDENTIFIER encoding (for example no OID
123 currently exists for a particular algorithm). As a result they cannot
124 be encoded or decoded as part of ASN.1 structures. Applications can
125 determine if there is a corresponding OBJECT IDENTIFIER by checking
126 OBJ_length() is not zero.
127
128 These functions cannot return const because an ASN1_OBJECT can
129 represent both an internal, constant, OID and a dynamically-created
130 one. The latter cannot be constant because it needs to be freed after
131 use.
132
134 OBJ_nid2obj() returns an ASN1_OBJECT structure or NULL is an error
135 occurred.
136
137 OBJ_nid2ln() and OBJ_nid2sn() returns a valid string or NULL on error.
138
139 OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() and OBJ_txt2nid() return a
140 NID or NID_undef on error.
141
143 Create an object for commonName:
144
145 ASN1_OBJECT *o = OBJ_nid2obj(NID_commonName);
146
147 Check if an object is commonName
148
149 if (OBJ_obj2nid(obj) == NID_commonName)
150 /* Do something */
151
152 Create a new NID and initialize an object from it:
153
154 int new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
155 ASN1_OBJECT *obj = OBJ_nid2obj(new_nid);
156
157 Create a new object directly:
158
159 obj = OBJ_txt2obj("1.2.3.4", 1);
160
162 OBJ_obj2txt() is awkward and messy to use: it doesn't follow the
163 convention of other OpenSSL functions where the buffer can be set to
164 NULL to determine the amount of data that should be written. Instead
165 buf must point to a valid buffer and buf_len should be set to a
166 positive value. A buffer length of 80 should be more than enough to
167 handle any OID encountered in practice.
168
170 ERR_get_error(3)
171
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-2019 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.1d 2019-10-03 OBJ_NID2OBJ(3)