Fix i2d_X509_AUX, update docs and add tests
[openssl.git] / doc / crypto / OBJ_nid2obj.pod
1 =pod
2
3 =head1 NAME
4
5 OBJ_nid2obj, OBJ_nid2ln, OBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid, OBJ_ln2nid, OBJ_sn2nid,
6 OBJ_cmp, OBJ_dup, OBJ_txt2obj, OBJ_obj2txt, OBJ_create, OBJ_cleanup - ASN1 object utility
7 functions
8
9 =head1 SYNOPSIS
10
11  #include <openssl/objects.h>
12
13  ASN1_OBJECT * OBJ_nid2obj(int n);
14  const char *  OBJ_nid2ln(int n);
15  const char *  OBJ_nid2sn(int n);
16
17  int OBJ_obj2nid(const ASN1_OBJECT *o);
18  int OBJ_ln2nid(const char *ln);
19  int OBJ_sn2nid(const char *sn);
20
21  int OBJ_txt2nid(const char *s);
22
23  ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name);
24  int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
25
26  int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);
27  ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o);
28
29  int OBJ_create(const char *oid,const char *sn,const char *ln);
30
31  size_t OBJ_length(const ASN1_OBJECT *obj);
32  const unsigned char *OBJ_get0_data(const ASN1_OBJECT *obj);
33
34 Deprecated:
35
36  #if OPENSSL_API_COMPAT < 0x10100000L
37  void OBJ_cleanup(void)
38  #endif
39
40 =head1 DESCRIPTION
41
42 The ASN1 object utility functions process ASN1_OBJECT structures which are
43 a representation of the ASN1 OBJECT IDENTIFIER (OID) type.
44
45 OBJ_nid2obj(), OBJ_nid2ln() and OBJ_nid2sn() convert the NID B<n> to 
46 an ASN1_OBJECT structure, its long name and its short name respectively,
47 or B<NULL> is an error occurred.
48
49 OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() return the corresponding NID
50 for the object B<o>, the long name <ln> or the short name <sn> respectively
51 or NID_undef if an error occurred.
52
53 OBJ_txt2nid() returns NID corresponding to text string <s>. B<s> can be
54 a long name, a short name or the numerical representation of an object.
55
56 OBJ_txt2obj() converts the text string B<s> into an ASN1_OBJECT structure.
57 If B<no_name> is 0 then long names and short names will be interpreted
58 as well as numerical forms. If B<no_name> is 1 only the numerical form
59 is acceptable.
60
61 OBJ_obj2txt() converts the B<ASN1_OBJECT> B<a> into a textual representation.
62 The representation is written as a null terminated string to B<buf>
63 at most B<buf_len> bytes are written, truncating the result if necessary.
64 The total amount of space required is returned. If B<no_name> is 0 then
65 if the object has a long or short name then that will be used, otherwise
66 the numerical form will be used. If B<no_name> is 1 then the numerical
67 form will always be used.
68
69 OBJ_cmp() compares B<a> to B<b>. If the two are identical 0 is returned.
70
71 OBJ_dup() returns a copy of B<o>.
72
73 OBJ_create() adds a new object to the internal table. B<oid> is the 
74 numerical form of the object, B<sn> the short name and B<ln> the
75 long name. A new NID is returned for the created object.
76
77 OBJ_length() returns the size of the content octets of B<obj>.
78
79 OBJ_get0_data() returns a pointer to the content octets of B<obj>.
80 The returned pointer is an internal pointer which B<must not> be freed.
81
82 In OpenSSL versions prior to 1.1.0 OBJ_cleanup() cleaned up OpenSSLs internal
83 object table and was called before an application exits if any new objects were
84 added using OBJ_create(). This function is deprecated in version 1.1.0 and now
85 does nothing if called. No explicit de-initialisation is now required. See
86 L<OPENSSL_init_crypto(3)> for further information.
87
88 =head1 NOTES
89
90 Objects in OpenSSL can have a short name, a long name and a numerical
91 identifier (NID) associated with them. A standard set of objects is
92 represented in an internal table. The appropriate values are defined
93 in the header file B<objects.h>.
94
95 For example the OID for commonName has the following definitions:
96
97  #define SN_commonName                   "CN"
98  #define LN_commonName                   "commonName"
99  #define NID_commonName                  13
100
101 New objects can be added by calling OBJ_create().
102
103 Table objects have certain advantages over other objects: for example
104 their NIDs can be used in a C language switch statement. They are
105 also static constant structures which are shared: that is there
106 is only a single constant structure for each table object.
107
108 Objects which are not in the table have the NID value NID_undef.
109
110 Objects do not need to be in the internal tables to be processed,
111 the functions OBJ_txt2obj() and OBJ_obj2txt() can process the numerical
112 form of an OID.
113
114 Some objects are used to represent algorithms which do not have a
115 corresponding ASN.1 OBJECT IDENTIFIER encoding (for example no OID currently
116 exists for a particular algorithm). As a result they B<cannot> be encoded or
117 decoded as part of ASN.1 structures. Applications can determine if there
118 is a corresponding OBJECT IDENTIFIER by checking OBJ_length() is not zero.
119
120 =head1 EXAMPLES
121
122 Create an object for B<commonName>:
123
124  ASN1_OBJECT *o;
125  o = OBJ_nid2obj(NID_commonName);
126
127 Check if an object is B<commonName>
128
129  if (OBJ_obj2nid(obj) == NID_commonName)
130         /* Do something */
131
132 Create a new NID and initialize an object from it:
133
134  int new_nid;
135  ASN1_OBJECT *obj;
136  new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
137
138  obj = OBJ_nid2obj(new_nid);
139  
140 Create a new object directly:
141
142  obj = OBJ_txt2obj("1.2.3.4", 1);
143
144 =head1 BUGS
145
146 OBJ_obj2txt() is awkward and messy to use: it doesn't follow the 
147 convention of other OpenSSL functions where the buffer can be set
148 to B<NULL> to determine the amount of data that should be written.
149 Instead B<buf> must point to a valid buffer and B<buf_len> should
150 be set to a positive value. A buffer length of 80 should be more
151 than enough to handle any OID encountered in practice.
152
153 =head1 RETURN VALUES
154
155 OBJ_nid2obj() returns an B<ASN1_OBJECT> structure or B<NULL> is an
156 error occurred.
157
158 OBJ_nid2ln() and OBJ_nid2sn() returns a valid string or B<NULL>
159 on error.
160
161 OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() and OBJ_txt2nid() return
162 a NID or B<NID_undef> on error.
163
164 =head1 SEE ALSO
165
166 L<ERR_get_error(3)>
167
168 =head1 HISTORY
169
170 OBJ_cleanup() was deprecated in OpenSSL 1.1.0.
171
172 =cut