xref: /freebsd-src/crypto/openssl/doc/man3/OBJ_nid2obj.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk Kimi2t_ASN1_OBJECT,
6e71b7053SJung-uk KimOBJ_length, OBJ_get0_data, OBJ_nid2obj, OBJ_nid2ln,
7e71b7053SJung-uk KimOBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid, OBJ_ln2nid, OBJ_sn2nid, OBJ_cmp,
8*b077aed3SPierre ProncheryOBJ_dup, OBJ_txt2obj, OBJ_obj2txt, OBJ_create, OBJ_cleanup, OBJ_add_sigid
9e71b7053SJung-uk Kim- ASN1 object utility functions
10e71b7053SJung-uk Kim
11e71b7053SJung-uk Kim=head1 SYNOPSIS
12e71b7053SJung-uk Kim
13e71b7053SJung-uk Kim #include <openssl/objects.h>
14e71b7053SJung-uk Kim
15e71b7053SJung-uk Kim ASN1_OBJECT *OBJ_nid2obj(int n);
16e71b7053SJung-uk Kim const char *OBJ_nid2ln(int n);
17e71b7053SJung-uk Kim const char *OBJ_nid2sn(int n);
18e71b7053SJung-uk Kim
19e71b7053SJung-uk Kim int OBJ_obj2nid(const ASN1_OBJECT *o);
20e71b7053SJung-uk Kim int OBJ_ln2nid(const char *ln);
21e71b7053SJung-uk Kim int OBJ_sn2nid(const char *sn);
22e71b7053SJung-uk Kim
23e71b7053SJung-uk Kim int OBJ_txt2nid(const char *s);
24e71b7053SJung-uk Kim
25e71b7053SJung-uk Kim ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name);
26e71b7053SJung-uk Kim int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
27e71b7053SJung-uk Kim
28e71b7053SJung-uk Kim int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a);
29e71b7053SJung-uk Kim
30e71b7053SJung-uk Kim int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);
31e71b7053SJung-uk Kim ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o);
32e71b7053SJung-uk Kim
33e71b7053SJung-uk Kim int OBJ_create(const char *oid, const char *sn, const char *ln);
34e71b7053SJung-uk Kim
35e71b7053SJung-uk Kim size_t OBJ_length(const ASN1_OBJECT *obj);
36e71b7053SJung-uk Kim const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj);
37e71b7053SJung-uk Kim
38*b077aed3SPierre Pronchery int OBJ_add_sigid(int signid, int dig_id, int pkey_id);
39e71b7053SJung-uk Kim
40*b077aed3SPierre ProncheryThe following function has been deprecated since OpenSSL 1.1.0, and can be
41*b077aed3SPierre Proncheryhidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
42*b077aed3SPierre Proncherysee L<openssl_user_macros(7)>:
43*b077aed3SPierre Pronchery
44*b077aed3SPierre Pronchery void OBJ_cleanup(void);
45e71b7053SJung-uk Kim
46e71b7053SJung-uk Kim=head1 DESCRIPTION
47e71b7053SJung-uk Kim
48e71b7053SJung-uk KimThe ASN1 object utility functions process ASN1_OBJECT structures which are
49e71b7053SJung-uk Kima representation of the ASN1 OBJECT IDENTIFIER (OID) type.
50e71b7053SJung-uk KimFor convenience, OIDs are usually represented in source code as numeric
51*b077aed3SPierre Proncheryidentifiers, or B<NID>s.  OpenSSL has an internal table of OIDs that
52e71b7053SJung-uk Kimare generated when the library is built, and their corresponding NIDs
53e71b7053SJung-uk Kimare available as defined constants.  For the functions below, application
54e71b7053SJung-uk Kimcode should treat all returned values -- OIDs, NIDs, or names -- as
55e71b7053SJung-uk Kimconstants.
56e71b7053SJung-uk Kim
57b2bf0c7eSJung-uk KimOBJ_nid2obj(), OBJ_nid2ln() and OBJ_nid2sn() convert the NID I<n> to
58e71b7053SJung-uk Kiman ASN1_OBJECT structure, its long name and its short name respectively,
59e71b7053SJung-uk Kimor B<NULL> if an error occurred.
60e71b7053SJung-uk Kim
61e71b7053SJung-uk KimOBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() return the corresponding NID
62*b077aed3SPierre Proncheryfor the object I<o>, the long name I<ln> or the short name I<sn> respectively
63e71b7053SJung-uk Kimor NID_undef if an error occurred.
64e71b7053SJung-uk Kim
65b2bf0c7eSJung-uk KimOBJ_txt2nid() returns NID corresponding to text string I<s>. I<s> can be
66e71b7053SJung-uk Kima long name, a short name or the numerical representation of an object.
67e71b7053SJung-uk Kim
68b2bf0c7eSJung-uk KimOBJ_txt2obj() converts the text string I<s> into an ASN1_OBJECT structure.
69b2bf0c7eSJung-uk KimIf I<no_name> is 0 then long names and short names will be interpreted
70b2bf0c7eSJung-uk Kimas well as numerical forms. If I<no_name> is 1 only the numerical form
71e71b7053SJung-uk Kimis acceptable.
72e71b7053SJung-uk Kim
735ac766abSJung-uk KimOBJ_obj2txt() converts the B<ASN1_OBJECT> I<a> into a textual representation.
745ac766abSJung-uk KimUnless I<buf> is NULL,
755ac766abSJung-uk Kimthe representation is written as a NUL-terminated string to I<buf>, where
765ac766abSJung-uk Kimat most I<buf_len> bytes are written, truncating the result if necessary.
775ac766abSJung-uk KimIn any case it returns the total string length, excluding the NUL character,
785ac766abSJung-uk Kimrequired for non-truncated representation, or -1 on error.
795ac766abSJung-uk KimIf I<no_name> is 0 then if the object has a long or short name
805ac766abSJung-uk Kimthen that will be used, otherwise the numerical form will be used.
815ac766abSJung-uk KimIf I<no_name> is 1 then the numerical form will always be used.
82e71b7053SJung-uk Kim
83b2bf0c7eSJung-uk Kimi2t_ASN1_OBJECT() is the same as OBJ_obj2txt() with the I<no_name> set to zero.
84e71b7053SJung-uk Kim
85b2bf0c7eSJung-uk KimOBJ_cmp() compares I<a> to I<b>. If the two are identical 0 is returned.
86e71b7053SJung-uk Kim
87b2bf0c7eSJung-uk KimOBJ_dup() returns a copy of I<o>.
88e71b7053SJung-uk Kim
89b2bf0c7eSJung-uk KimOBJ_create() adds a new object to the internal table. I<oid> is the
90b2bf0c7eSJung-uk Kimnumerical form of the object, I<sn> the short name and I<ln> the
91e71b7053SJung-uk Kimlong name. A new NID is returned for the created object in case of
92e71b7053SJung-uk Kimsuccess and NID_undef in case of failure.
93e71b7053SJung-uk Kim
94b2bf0c7eSJung-uk KimOBJ_length() returns the size of the content octets of I<obj>.
95e71b7053SJung-uk Kim
96b2bf0c7eSJung-uk KimOBJ_get0_data() returns a pointer to the content octets of I<obj>.
97e71b7053SJung-uk KimThe returned pointer is an internal pointer which B<must not> be freed.
98e71b7053SJung-uk Kim
99*b077aed3SPierre ProncheryOBJ_add_sigid() creates a new composite "Signature Algorithm" that associates a
100*b077aed3SPierre Proncherygiven NID with two other NIDs - one representing the underlying signature
101*b077aed3SPierre Proncheryalgorithm and the other representing a digest algorithm to be used in
102*b077aed3SPierre Proncheryconjunction with it. I<signid> represents the NID for the composite "Signature
103*b077aed3SPierre ProncheryAlgorithm", I<dig_id> is the NID for the digest algorithm and I<pkey_id> is the
104*b077aed3SPierre ProncheryNID for the underlying signature algorithm. As there are signature algorithms
105*b077aed3SPierre Proncherythat do not require a digest, NID_undef is a valid I<dig_id>.
106*b077aed3SPierre Pronchery
107e71b7053SJung-uk KimOBJ_cleanup() releases any resources allocated by creating new objects.
108e71b7053SJung-uk Kim
109e71b7053SJung-uk Kim=head1 NOTES
110e71b7053SJung-uk Kim
111e71b7053SJung-uk KimObjects in OpenSSL can have a short name, a long name and a numerical
112e71b7053SJung-uk Kimidentifier (NID) associated with them. A standard set of objects is
113e71b7053SJung-uk Kimrepresented in an internal table. The appropriate values are defined
114e71b7053SJung-uk Kimin the header file B<objects.h>.
115e71b7053SJung-uk Kim
116e71b7053SJung-uk KimFor example the OID for commonName has the following definitions:
117e71b7053SJung-uk Kim
118e71b7053SJung-uk Kim #define SN_commonName                   "CN"
119e71b7053SJung-uk Kim #define LN_commonName                   "commonName"
120e71b7053SJung-uk Kim #define NID_commonName                  13
121e71b7053SJung-uk Kim
122e71b7053SJung-uk KimNew objects can be added by calling OBJ_create().
123e71b7053SJung-uk Kim
124e71b7053SJung-uk KimTable objects have certain advantages over other objects: for example
125e71b7053SJung-uk Kimtheir NIDs can be used in a C language switch statement. They are
126e71b7053SJung-uk Kimalso static constant structures which are shared: that is there
127e71b7053SJung-uk Kimis only a single constant structure for each table object.
128e71b7053SJung-uk Kim
129e71b7053SJung-uk KimObjects which are not in the table have the NID value NID_undef.
130e71b7053SJung-uk Kim
131e71b7053SJung-uk KimObjects do not need to be in the internal tables to be processed,
132e71b7053SJung-uk Kimthe functions OBJ_txt2obj() and OBJ_obj2txt() can process the numerical
133e71b7053SJung-uk Kimform of an OID.
134e71b7053SJung-uk Kim
135e71b7053SJung-uk KimSome objects are used to represent algorithms which do not have a
136e71b7053SJung-uk Kimcorresponding ASN.1 OBJECT IDENTIFIER encoding (for example no OID currently
137e71b7053SJung-uk Kimexists for a particular algorithm). As a result they B<cannot> be encoded or
138e71b7053SJung-uk Kimdecoded as part of ASN.1 structures. Applications can determine if there
139e71b7053SJung-uk Kimis a corresponding OBJECT IDENTIFIER by checking OBJ_length() is not zero.
140e71b7053SJung-uk Kim
141e71b7053SJung-uk KimThese functions cannot return B<const> because an B<ASN1_OBJECT> can
142e71b7053SJung-uk Kimrepresent both an internal, constant, OID and a dynamically-created one.
143e71b7053SJung-uk KimThe latter cannot be constant because it needs to be freed after use.
144e71b7053SJung-uk Kim
145610a21fdSJung-uk Kim=head1 RETURN VALUES
146610a21fdSJung-uk Kim
147610a21fdSJung-uk KimOBJ_nid2obj() returns an B<ASN1_OBJECT> structure or B<NULL> is an
148610a21fdSJung-uk Kimerror occurred.
149610a21fdSJung-uk Kim
150610a21fdSJung-uk KimOBJ_nid2ln() and OBJ_nid2sn() returns a valid string or B<NULL>
151610a21fdSJung-uk Kimon error.
152610a21fdSJung-uk Kim
153610a21fdSJung-uk KimOBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() and OBJ_txt2nid() return
154610a21fdSJung-uk Kima NID or B<NID_undef> on error.
155610a21fdSJung-uk Kim
1565ac766abSJung-uk KimOBJ_add_sigid() returns 1 on success or 0 on error.
1575ac766abSJung-uk Kim
1585ac766abSJung-uk Kimi2t_ASN1_OBJECT() an OBJ_obj2txt() return -1 on error.
1595ac766abSJung-uk KimOn success, they return the length of the string written to I<buf> if I<buf> is
1605ac766abSJung-uk Kimnot NULL and I<buf_len> is big enough, otherwise the total string length.
1615ac766abSJung-uk KimNote that this does not count the trailing NUL character.
1625ac766abSJung-uk Kim
163e71b7053SJung-uk Kim=head1 EXAMPLES
164e71b7053SJung-uk Kim
165e71b7053SJung-uk KimCreate an object for B<commonName>:
166e71b7053SJung-uk Kim
167e71b7053SJung-uk Kim ASN1_OBJECT *o = OBJ_nid2obj(NID_commonName);
168e71b7053SJung-uk Kim
169e71b7053SJung-uk KimCheck if an object is B<commonName>
170e71b7053SJung-uk Kim
171e71b7053SJung-uk Kim if (OBJ_obj2nid(obj) == NID_commonName)
172e71b7053SJung-uk Kim     /* Do something */
173e71b7053SJung-uk Kim
174e71b7053SJung-uk KimCreate a new NID and initialize an object from it:
175e71b7053SJung-uk Kim
176e71b7053SJung-uk Kim int new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
177e71b7053SJung-uk Kim ASN1_OBJECT *obj = OBJ_nid2obj(new_nid);
178e71b7053SJung-uk Kim
179e71b7053SJung-uk KimCreate a new object directly:
180e71b7053SJung-uk Kim
181e71b7053SJung-uk Kim obj = OBJ_txt2obj("1.2.3.4", 1);
182e71b7053SJung-uk Kim
183*b077aed3SPierre Pronchery=head1 BUGS
184*b077aed3SPierre Pronchery
185*b077aed3SPierre ProncheryNeither OBJ_create() nor OBJ_add_sigid() do any locking and are thus not
186*b077aed3SPierre Proncherythread safe.  Moreover, none of the other functions should be called while
187*b077aed3SPierre Proncheryconcurrent calls to these two functions are possible.
188*b077aed3SPierre Pronchery
189e71b7053SJung-uk Kim=head1 SEE ALSO
190e71b7053SJung-uk Kim
191e71b7053SJung-uk KimL<ERR_get_error(3)>
192e71b7053SJung-uk Kim
193e71b7053SJung-uk Kim=head1 HISTORY
194e71b7053SJung-uk Kim
195e71b7053SJung-uk KimOBJ_cleanup() was deprecated in OpenSSL 1.1.0 by L<OPENSSL_init_crypto(3)>
196e71b7053SJung-uk Kimand should not be used.
197e71b7053SJung-uk Kim
198e71b7053SJung-uk Kim=head1 COPYRIGHT
199e71b7053SJung-uk Kim
200*b077aed3SPierre ProncheryCopyright 2002-2021 The OpenSSL Project Authors. All Rights Reserved.
201e71b7053SJung-uk Kim
202*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
203e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
204e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
205e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
206e71b7053SJung-uk Kim
207e71b7053SJung-uk Kim=cut
208