xref: /netbsd-src/crypto/external/bsd/openssl/dist/doc/man3/OBJ_nid2obj.pod (revision b0d1725196a7921d003d2c66a14f186abda4176b)
113d40330Schristos=pod
213d40330Schristos
313d40330Schristos=head1 NAME
413d40330Schristos
513d40330Schristosi2t_ASN1_OBJECT,
613d40330SchristosOBJ_length, OBJ_get0_data, OBJ_nid2obj, OBJ_nid2ln,
713d40330SchristosOBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid, OBJ_ln2nid, OBJ_sn2nid, OBJ_cmp,
8*b0d17251SchristosOBJ_dup, OBJ_txt2obj, OBJ_obj2txt, OBJ_create, OBJ_cleanup, OBJ_add_sigid
913d40330Schristos- ASN1 object utility functions
1013d40330Schristos
1113d40330Schristos=head1 SYNOPSIS
1213d40330Schristos
1313d40330Schristos #include <openssl/objects.h>
1413d40330Schristos
1513d40330Schristos ASN1_OBJECT *OBJ_nid2obj(int n);
1613d40330Schristos const char *OBJ_nid2ln(int n);
1713d40330Schristos const char *OBJ_nid2sn(int n);
1813d40330Schristos
1913d40330Schristos int OBJ_obj2nid(const ASN1_OBJECT *o);
2013d40330Schristos int OBJ_ln2nid(const char *ln);
2113d40330Schristos int OBJ_sn2nid(const char *sn);
2213d40330Schristos
2313d40330Schristos int OBJ_txt2nid(const char *s);
2413d40330Schristos
2513d40330Schristos ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name);
2613d40330Schristos int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
2713d40330Schristos
2813d40330Schristos int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a);
2913d40330Schristos
3013d40330Schristos int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b);
3113d40330Schristos ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o);
3213d40330Schristos
3313d40330Schristos int OBJ_create(const char *oid, const char *sn, const char *ln);
3413d40330Schristos
3513d40330Schristos size_t OBJ_length(const ASN1_OBJECT *obj);
3613d40330Schristos const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj);
3713d40330Schristos
38*b0d17251Schristos int OBJ_add_sigid(int signid, int dig_id, int pkey_id);
3913d40330Schristos
40*b0d17251SchristosThe following function has been deprecated since OpenSSL 1.1.0, and can be
41*b0d17251Schristoshidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
42*b0d17251Schristossee L<openssl_user_macros(7)>:
43*b0d17251Schristos
44*b0d17251Schristos void OBJ_cleanup(void);
4513d40330Schristos
4613d40330Schristos=head1 DESCRIPTION
4713d40330Schristos
4813d40330SchristosThe ASN1 object utility functions process ASN1_OBJECT structures which are
4913d40330Schristosa representation of the ASN1 OBJECT IDENTIFIER (OID) type.
5013d40330SchristosFor convenience, OIDs are usually represented in source code as numeric
51*b0d17251Schristosidentifiers, or B<NID>s.  OpenSSL has an internal table of OIDs that
5213d40330Schristosare generated when the library is built, and their corresponding NIDs
5313d40330Schristosare available as defined constants.  For the functions below, application
5413d40330Schristoscode should treat all returned values -- OIDs, NIDs, or names -- as
5513d40330Schristosconstants.
5613d40330Schristos
5721497c5cSchristosOBJ_nid2obj(), OBJ_nid2ln() and OBJ_nid2sn() convert the NID I<n> to
5813d40330Schristosan ASN1_OBJECT structure, its long name and its short name respectively,
5913d40330Schristosor B<NULL> if an error occurred.
6013d40330Schristos
6113d40330SchristosOBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() return the corresponding NID
62*b0d17251Schristosfor the object I<o>, the long name I<ln> or the short name I<sn> respectively
6313d40330Schristosor NID_undef if an error occurred.
6413d40330Schristos
6521497c5cSchristosOBJ_txt2nid() returns NID corresponding to text string I<s>. I<s> can be
6613d40330Schristosa long name, a short name or the numerical representation of an object.
6713d40330Schristos
6821497c5cSchristosOBJ_txt2obj() converts the text string I<s> into an ASN1_OBJECT structure.
6921497c5cSchristosIf I<no_name> is 0 then long names and short names will be interpreted
7021497c5cSchristosas well as numerical forms. If I<no_name> is 1 only the numerical form
7113d40330Schristosis acceptable.
7213d40330Schristos
73d3425df3SchristosOBJ_obj2txt() converts the B<ASN1_OBJECT> I<a> into a textual representation.
74d3425df3SchristosUnless I<buf> is NULL,
75d3425df3Schristosthe representation is written as a NUL-terminated string to I<buf>, where
76d3425df3Schristosat most I<buf_len> bytes are written, truncating the result if necessary.
77d3425df3SchristosIn any case it returns the total string length, excluding the NUL character,
78d3425df3Schristosrequired for non-truncated representation, or -1 on error.
79d3425df3SchristosIf I<no_name> is 0 then if the object has a long or short name
80d3425df3Schristosthen that will be used, otherwise the numerical form will be used.
81d3425df3SchristosIf I<no_name> is 1 then the numerical form will always be used.
8213d40330Schristos
8321497c5cSchristosi2t_ASN1_OBJECT() is the same as OBJ_obj2txt() with the I<no_name> set to zero.
8413d40330Schristos
8521497c5cSchristosOBJ_cmp() compares I<a> to I<b>. If the two are identical 0 is returned.
8613d40330Schristos
8721497c5cSchristosOBJ_dup() returns a copy of I<o>.
8813d40330Schristos
8921497c5cSchristosOBJ_create() adds a new object to the internal table. I<oid> is the
9021497c5cSchristosnumerical form of the object, I<sn> the short name and I<ln> the
9113d40330Schristoslong name. A new NID is returned for the created object in case of
9213d40330Schristossuccess and NID_undef in case of failure.
9313d40330Schristos
9421497c5cSchristosOBJ_length() returns the size of the content octets of I<obj>.
9513d40330Schristos
9621497c5cSchristosOBJ_get0_data() returns a pointer to the content octets of I<obj>.
9713d40330SchristosThe returned pointer is an internal pointer which B<must not> be freed.
9813d40330Schristos
99*b0d17251SchristosOBJ_add_sigid() creates a new composite "Signature Algorithm" that associates a
100*b0d17251Schristosgiven NID with two other NIDs - one representing the underlying signature
101*b0d17251Schristosalgorithm and the other representing a digest algorithm to be used in
102*b0d17251Schristosconjunction with it. I<signid> represents the NID for the composite "Signature
103*b0d17251SchristosAlgorithm", I<dig_id> is the NID for the digest algorithm and I<pkey_id> is the
104*b0d17251SchristosNID for the underlying signature algorithm. As there are signature algorithms
105*b0d17251Schristosthat do not require a digest, NID_undef is a valid I<dig_id>.
106*b0d17251Schristos
10713d40330SchristosOBJ_cleanup() releases any resources allocated by creating new objects.
10813d40330Schristos
10913d40330Schristos=head1 NOTES
11013d40330Schristos
11113d40330SchristosObjects in OpenSSL can have a short name, a long name and a numerical
11213d40330Schristosidentifier (NID) associated with them. A standard set of objects is
11313d40330Schristosrepresented in an internal table. The appropriate values are defined
11413d40330Schristosin the header file B<objects.h>.
11513d40330Schristos
11613d40330SchristosFor example the OID for commonName has the following definitions:
11713d40330Schristos
11813d40330Schristos #define SN_commonName                   "CN"
11913d40330Schristos #define LN_commonName                   "commonName"
12013d40330Schristos #define NID_commonName                  13
12113d40330Schristos
12213d40330SchristosNew objects can be added by calling OBJ_create().
12313d40330Schristos
12413d40330SchristosTable objects have certain advantages over other objects: for example
12513d40330Schristostheir NIDs can be used in a C language switch statement. They are
12613d40330Schristosalso static constant structures which are shared: that is there
12713d40330Schristosis only a single constant structure for each table object.
12813d40330Schristos
12913d40330SchristosObjects which are not in the table have the NID value NID_undef.
13013d40330Schristos
13113d40330SchristosObjects do not need to be in the internal tables to be processed,
13213d40330Schristosthe functions OBJ_txt2obj() and OBJ_obj2txt() can process the numerical
13313d40330Schristosform of an OID.
13413d40330Schristos
13513d40330SchristosSome objects are used to represent algorithms which do not have a
13613d40330Schristoscorresponding ASN.1 OBJECT IDENTIFIER encoding (for example no OID currently
13713d40330Schristosexists for a particular algorithm). As a result they B<cannot> be encoded or
13813d40330Schristosdecoded as part of ASN.1 structures. Applications can determine if there
13913d40330Schristosis a corresponding OBJECT IDENTIFIER by checking OBJ_length() is not zero.
14013d40330Schristos
14113d40330SchristosThese functions cannot return B<const> because an B<ASN1_OBJECT> can
14213d40330Schristosrepresent both an internal, constant, OID and a dynamically-created one.
14313d40330SchristosThe latter cannot be constant because it needs to be freed after use.
14413d40330Schristos
145a3b08d93Schristos=head1 RETURN VALUES
146a3b08d93Schristos
147a3b08d93SchristosOBJ_nid2obj() returns an B<ASN1_OBJECT> structure or B<NULL> is an
148a3b08d93Schristoserror occurred.
149a3b08d93Schristos
150a3b08d93SchristosOBJ_nid2ln() and OBJ_nid2sn() returns a valid string or B<NULL>
151a3b08d93Schristoson error.
152a3b08d93Schristos
153a3b08d93SchristosOBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() and OBJ_txt2nid() return
154a3b08d93Schristosa NID or B<NID_undef> on error.
155a3b08d93Schristos
156d3425df3SchristosOBJ_add_sigid() returns 1 on success or 0 on error.
157d3425df3Schristos
158d3425df3Schristosi2t_ASN1_OBJECT() an OBJ_obj2txt() return -1 on error.
159d3425df3SchristosOn success, they return the length of the string written to I<buf> if I<buf> is
160d3425df3Schristosnot NULL and I<buf_len> is big enough, otherwise the total string length.
161d3425df3SchristosNote that this does not count the trailing NUL character.
162d3425df3Schristos
16313d40330Schristos=head1 EXAMPLES
16413d40330Schristos
16513d40330SchristosCreate an object for B<commonName>:
16613d40330Schristos
16713d40330Schristos ASN1_OBJECT *o = OBJ_nid2obj(NID_commonName);
16813d40330Schristos
16913d40330SchristosCheck if an object is B<commonName>
17013d40330Schristos
17113d40330Schristos if (OBJ_obj2nid(obj) == NID_commonName)
17213d40330Schristos     /* Do something */
17313d40330Schristos
17413d40330SchristosCreate a new NID and initialize an object from it:
17513d40330Schristos
17613d40330Schristos int new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
17713d40330Schristos ASN1_OBJECT *obj = OBJ_nid2obj(new_nid);
17813d40330Schristos
17913d40330SchristosCreate a new object directly:
18013d40330Schristos
18113d40330Schristos obj = OBJ_txt2obj("1.2.3.4", 1);
18213d40330Schristos
183*b0d17251Schristos=head1 BUGS
184*b0d17251Schristos
185*b0d17251SchristosNeither OBJ_create() nor OBJ_add_sigid() do any locking and are thus not
186*b0d17251Schristosthread safe.  Moreover, none of the other functions should be called while
187*b0d17251Schristosconcurrent calls to these two functions are possible.
188*b0d17251Schristos
18913d40330Schristos=head1 SEE ALSO
19013d40330Schristos
19113d40330SchristosL<ERR_get_error(3)>
19213d40330Schristos
19313d40330Schristos=head1 HISTORY
19413d40330Schristos
19513d40330SchristosOBJ_cleanup() was deprecated in OpenSSL 1.1.0 by L<OPENSSL_init_crypto(3)>
19613d40330Schristosand should not be used.
19713d40330Schristos
19813d40330Schristos=head1 COPYRIGHT
19913d40330Schristos
200*b0d17251SchristosCopyright 2002-2021 The OpenSSL Project Authors. All Rights Reserved.
20113d40330Schristos
202*b0d17251SchristosLicensed under the Apache License 2.0 (the "License").  You may not use
20313d40330Schristosthis file except in compliance with the License.  You can obtain a copy
20413d40330Schristosin the file LICENSE in the source distribution or at
20513d40330SchristosL<https://www.openssl.org/source/license.html>.
20613d40330Schristos
20713d40330Schristos=cut
208