Debian Codegraph @

upstream/debian-unstable/man3/OBJ_nid2obj.3ssl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "OBJ_NID2OBJ 3SSL"
58 .TH OBJ_NID2OBJ 3SSL 2026-04-07 3.6.2 OpenSSL
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 i2t_ASN1_OBJECT,
65 OBJ_length, OBJ_get0_data, OBJ_nid2obj, OBJ_nid2ln,
66 OBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid, OBJ_ln2nid, OBJ_sn2nid, OBJ_cmp,
67 OBJ_dup, OBJ_txt2obj, OBJ_obj2txt, OBJ_create, OBJ_cleanup, OBJ_add_sigid
68 \&\- ASN1 object utility functions
69 .SH SYNOPSIS
70 .IX Header "SYNOPSIS"
71 .Vb 1
72 \& #include <openssl/objects.h>
73 \&
74 \& ASN1_OBJECT *OBJ_nid2obj(int n);
75 \& const char *OBJ_nid2ln(int n);
76 \& const char *OBJ_nid2sn(int n);
77 \&
78 \& int OBJ_obj2nid(const ASN1_OBJECT *o);
79 \& int OBJ_ln2nid(const char *ln);
80 \& int OBJ_sn2nid(const char *sn);
81 \&
82 \& int OBJ_txt2nid(const char *s);
83 \&
84 \& ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name);
85 \& int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
86 \&
87 \& int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a);
88 \&
89 \& int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);
90 \& ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o);
91 \&
92 \& int OBJ_create(const char *oid, const char *sn, const char *ln);
93 \&
94 \& size_t OBJ_length(const ASN1_OBJECT *obj);
95 \& const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj);
96 \&
97 \& int OBJ_add_sigid(int signid, int dig_id, int pkey_id);
98 .Ve
99 .PP
100 The following function has been deprecated since OpenSSL 1.1.0, and can be
101 hidden entirely by defining \fBOPENSSL_API_COMPAT\fR with a suitable version value,
102 see \fBopenssl_user_macros\fR\|(7):
103 .PP
104 .Vb 1
105 \& void OBJ_cleanup(void);
106 .Ve
107 .SH DESCRIPTION
108 .IX Header "DESCRIPTION"
109 The ASN1 object utility functions process ASN1_OBJECT structures which are
110 a representation of the ASN1 OBJECT IDENTIFIER (OID) type.
111 For convenience, OIDs are usually represented in source code as numeric
112 identifiers, or \fBNID\fRs. OpenSSL has an internal table of OIDs that
113 are generated when the library is built, and their corresponding NIDs
114 are available as defined constants. For the functions below, application
115 code should treat all returned values \-\- OIDs, NIDs, or names \-\- as
116 constants.
117 .PP
118 \&\fBOBJ_nid2obj()\fR, \fBOBJ_nid2ln()\fR and \fBOBJ_nid2sn()\fR convert the NID \fIn\fR to
119 an ASN1_OBJECT structure, its long name and its short name respectively,
120 or \fBNULL\fR if an error occurred.
121 .PP
122 \&\fBOBJ_obj2nid()\fR, \fBOBJ_ln2nid()\fR, \fBOBJ_sn2nid()\fR return the corresponding NID
123 for the object \fIo\fR, the long name \fIln\fR or the short name \fIsn\fR respectively
124 or NID_undef if an error occurred.
125 .PP
126 \&\fBOBJ_txt2nid()\fR returns NID corresponding to text string \fIs\fR. \fIs\fR can be
127 a long name, a short name or the numerical representation of an object.
128 .PP
129 \&\fBOBJ_txt2obj()\fR converts the text string \fIs\fR into an ASN1_OBJECT structure.
130 If \fIno_name\fR is 0 then long names and short names will be interpreted
131 as well as numerical forms. If \fIno_name\fR is 1 only the numerical form
132 is acceptable.
133 .PP
134 \&\fBOBJ_obj2txt()\fR converts the \fBASN1_OBJECT\fR \fIa\fR into a textual representation.
135 Unless \fIbuf\fR is NULL,
136 the representation is written as a NUL-terminated string to \fIbuf\fR, where
137 at most \fIbuf_len\fR bytes are written, truncating the result if necessary.
138 In any case it returns the total string length, excluding the NUL character,
139 required for non-truncated representation, or \-1 on error.
140 If \fIno_name\fR is 0 then if the object has a long or short name
141 then that will be used, otherwise the numerical form will be used.
142 If \fIno_name\fR is 1 then the numerical form will always be used.
143 .PP
144 \&\fBi2t_ASN1_OBJECT()\fR is the same as \fBOBJ_obj2txt()\fR with the \fIno_name\fR set to zero.
145 .PP
146 \&\fBOBJ_cmp()\fR compares \fIa\fR to \fIb\fR. If the two are identical 0 is returned.
147 .PP
148 \&\fBOBJ_dup()\fR returns a copy of \fIo\fR.
149 .PP
150 \&\fBOBJ_create()\fR adds a new object to the internal table. \fIoid\fR is the
151 numerical form of the object, \fIsn\fR the short name and \fIln\fR the
152 long name. A new NID is returned for the created object in case of
153 success and NID_undef in case of failure. Any of \fIoid\fR, \fIsn\fR and
154 \&\fIln\fR may be NULL, but not all at once.
155 .PP
156 \&\fBOBJ_length()\fR returns the size of the content octets of \fIobj\fR.
157 .PP
158 \&\fBOBJ_get0_data()\fR returns a pointer to the content octets of \fIobj\fR.
159 The returned pointer is an internal pointer which \fBmust not\fR be freed.
160 .PP
161 \&\fBOBJ_add_sigid()\fR creates a new composite "Signature Algorithm" that associates a
162 given NID with two other NIDs \- one representing the underlying signature
163 algorithm and the other representing a digest algorithm to be used in
164 conjunction with it. \fIsignid\fR represents the NID for the composite "Signature
165 Algorithm", \fIdig_id\fR is the NID for the digest algorithm and \fIpkey_id\fR is the
166 NID for the underlying signature algorithm. As there are signature algorithms
167 that do not require a digest, NID_undef is a valid \fIdig_id\fR.
168 .PP
169 \&\fBOBJ_cleanup()\fR releases any resources allocated by creating new objects.
170 .SH NOTES
171 .IX Header "NOTES"
172 Objects in OpenSSL can have a short name, a long name and a numerical
173 identifier (NID) associated with them. A standard set of objects is
174 represented in an internal table. The appropriate values are defined
175 in the header file \fBobjects.h\fR.
176 .PP
177 For example the OID for commonName has the following definitions:
178 .PP
179 .Vb 3
180 \& #define SN_commonName "CN"
181 \& #define LN_commonName "commonName"
182 \& #define NID_commonName 13
183 .Ve
184 .PP
185 New objects can be added by calling \fBOBJ_create()\fR.
186 .PP
187 Table objects have certain advantages over other objects: for example
188 their NIDs can be used in a C language switch statement. They are
189 also static constant structures which are shared: that is there
190 is only a single constant structure for each table object.
191 .PP
192 Objects which are not in the table have the NID value NID_undef.
193 .PP
194 Objects do not need to be in the internal tables to be processed,
195 the functions \fBOBJ_txt2obj()\fR and \fBOBJ_obj2txt()\fR can process the numerical
196 form of an OID.
197 .PP
198 Some objects are used to represent algorithms which do not have a
199 corresponding ASN.1 OBJECT IDENTIFIER encoding (for example no OID currently
200 exists for a particular algorithm). As a result they \fBcannot\fR be encoded or
201 decoded as part of ASN.1 structures. Applications can determine if there
202 is a corresponding OBJECT IDENTIFIER by checking \fBOBJ_length()\fR is not zero.
203 .PP
204 These functions cannot return \fBconst\fR because an \fBASN1_OBJECT\fR can
205 represent both an internal, constant, OID and a dynamically-created one.
206 The latter cannot be constant because it needs to be freed after use.
207 .PP
208 These functions were not thread safe in OpenSSL 3.0 and before.
209 .SH "RETURN VALUES"
210 .IX Header "RETURN VALUES"
211 \&\fBOBJ_nid2obj()\fR returns an \fBASN1_OBJECT\fR structure or \fBNULL\fR is an
212 error occurred.
213 .PP
214 \&\fBOBJ_nid2ln()\fR and \fBOBJ_nid2sn()\fR returns a valid string or \fBNULL\fR
215 on error.
216 .PP
217 \&\fBOBJ_obj2nid()\fR, \fBOBJ_ln2nid()\fR, \fBOBJ_sn2nid()\fR and \fBOBJ_txt2nid()\fR return
218 a NID or \fBNID_undef\fR on error.
219 .PP
220 \&\fBOBJ_add_sigid()\fR returns 1 on success or 0 on error.
221 .PP
222 \&\fBi2t_ASN1_OBJECT()\fR an \fBOBJ_obj2txt()\fR return \-1 on error.
223 On success, they return the length of the string written to \fIbuf\fR if \fIbuf\fR is
224 not NULL and \fIbuf_len\fR is big enough, otherwise the total string length.
225 Note that this does not count the trailing NUL character.
226 .SH EXAMPLES
227 .IX Header "EXAMPLES"
228 Create an object for \fBcommonName\fR:
229 .PP
230 .Vb 1
231 \& ASN1_OBJECT *o = OBJ_nid2obj(NID_commonName);
232 .Ve
233 .PP
234 Check if an object is \fBcommonName\fR
235 .PP
236 .Vb 2
237 \& if (OBJ_obj2nid(obj) == NID_commonName)
238 \& /* Do something */
239 .Ve
240 .PP
241 Create a new NID and initialize an object from it:
242 .PP
243 .Vb 2
244 \& int new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
245 \& ASN1_OBJECT *obj = OBJ_nid2obj(new_nid);
246 .Ve
247 .PP
248 Create a new object directly:
249 .PP
250 .Vb 1
251 \& obj = OBJ_txt2obj("1.2.3.4", 1);
252 .Ve
253 .SH "SEE ALSO"
254 .IX Header "SEE ALSO"
255 \&\fBERR_get_error\fR\|(3)
256 .SH HISTORY
257 .IX Header "HISTORY"
258 \&\fBOBJ_cleanup()\fR was deprecated in OpenSSL 1.1.0 by \fBOPENSSL_init_crypto\fR\|(3)
259 and should not be used.
260 .SH COPYRIGHT
261 .IX Header "COPYRIGHT"
262 Copyright 2002\-2021 The OpenSSL Project Authors. All Rights Reserved.
263 .PP
264 Licensed under the Apache License 2.0 (the "License"). You may not use
265 this file except in compliance with the License. You can obtain a copy
266 in the file LICENSE in the source distribution or at
267 <https://www.openssl.org/source/license.html>.