1OBJ_nid2obj(3)                      OpenSSL                     OBJ_nid2obj(3)
2
3
4

NAME

6       OBJ_nid2obj, OBJ_nid2ln, OBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid,
7       OBJ_ln2nid, OBJ_sn2nid, OBJ_cmp, OBJ_dup, OBJ_txt2obj, OBJ_obj2txt,
8       OBJ_create, OBJ_cleanup - ASN1 object utility functions
9

SYNOPSIS

11        ASN1_OBJECT * OBJ_nid2obj(int n);
12        const char *  OBJ_nid2ln(int n);
13        const char *  OBJ_nid2sn(int n);
14
15        int OBJ_obj2nid(const ASN1_OBJECT *o);
16        int OBJ_ln2nid(const char *ln);
17        int OBJ_sn2nid(const char *sn);
18
19        int OBJ_txt2nid(const char *s);
20
21        ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name);
22        int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
23
24        int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);
25        ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o);
26
27        int OBJ_create(const char *oid,const char *sn,const char *ln);
28        void OBJ_cleanup(void);
29

DESCRIPTION

31       The ASN1 object utility functions process ASN1_OBJECT structures which
32       are a representation of the ASN1 OBJECT IDENTIFIER (OID) type.
33
34       OBJ_nid2obj(), OBJ_nid2ln() and OBJ_nid2sn() convert the NID n to an
35       ASN1_OBJECT structure, its long name and its short name respectively,
36       or NULL is an error occurred.
37
38       OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() return the corresponding NID
39       for the object o, the long name <ln> or the short name <sn> respec‐
40       tively or NID_undef if an error occurred.
41
42       OBJ_txt2nid() returns NID corresponding to text string <s>. s can be a
43       long name, a short name or the numerical respresentation of an object.
44
45       OBJ_txt2obj() converts the text string s into an ASN1_OBJECT structure.
46       If no_name is 0 then long names and short names will be interpreted as
47       well as numerical forms. If no_name is 1 only the numerical form is
48       acceptable.
49
50       OBJ_obj2txt() converts the ASN1_OBJECT a into a textual representation.
51       The representation is written as a null terminated string to buf at
52       most buf_len bytes are written, truncating the result if necessary.
53       The total amount of space required is returned. If no_name is 0 then if
54       the object has a long or short name then that will be used, otherwise
55       the numerical form will be used. If no_name is 1 then the numerical
56       form will always be used.
57
58       OBJ_cmp() compares a to b. If the two are identical 0 is returned.
59
60       OBJ_dup() returns a copy of o.
61
62       OBJ_create() adds a new object to the internal table. oid is the numer‐
63       ical form of the object, sn the short name and ln the long name. A new
64       NID is returned for the created object.
65
66       OBJ_cleanup() cleans up OpenSSLs internal object table: this should be
67       called before an application exits if any new objects were added using
68       OBJ_create().
69

NOTES

71       Objects in OpenSSL can have a short name, a long name and a numerical
72       identifier (NID) associated with them. A standard set of objects is
73       represented in an internal table. The appropriate values are defined in
74       the header file objects.h.
75
76       For example the OID for commonName has the following definitions:
77
78        #define SN_commonName                   "CN"
79        #define LN_commonName                   "commonName"
80        #define NID_commonName                  13
81
82       New objects can be added by calling OBJ_create().
83
84       Table objects have certain advantages over other objects: for example
85       their NIDs can be used in a C language switch statement. They are also
86       static constant structures which are shared: that is there is only a
87       single constant structure for each table object.
88
89       Objects which are not in the table have the NID value NID_undef.
90
91       Objects do not need to be in the internal tables to be processed, the
92       functions OBJ_txt2obj() and OBJ_obj2txt() can process the numerical
93       form of an OID.
94

EXAMPLES

96       Create an object for commonName:
97
98        ASN1_OBJECT *o;
99        o = OBJ_nid2obj(NID_commonName);
100
101       Check if an object is commonName
102
103        if (OBJ_obj2nid(obj) == NID_commonName)
104               /* Do something */
105
106       Create a new NID and initialize an object from it:
107
108        int new_nid;
109        ASN1_OBJECT *obj;
110        new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
111
112        obj = OBJ_nid2obj(new_nid);
113
114       Create a new object directly:
115
116        obj = OBJ_txt2obj("1.2.3.4", 1);
117

BUGS

119       OBJ_obj2txt() is awkward and messy to use: it doesn't follow the con‐
120       vention of other OpenSSL functions where the buffer can be set to NULL
121       to determine the amount of data that should be written.  Instead buf
122       must point to a valid buffer and buf_len should be set to a positive
123       value. A buffer length of 80 should be more than enough to handle any
124       OID encountered in practice.
125

RETURN VALUES

127       OBJ_nid2obj() returns an ASN1_OBJECT structure or NULL is an error
128       occurred.
129
130       OBJ_nid2ln() and OBJ_nid2sn() returns a valid string or NULL on error.
131
132       OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() and OBJ_txt2nid() return a
133       NID or NID_undef on error.
134

SEE ALSO

136       ERR_get_error(3)
137

HISTORY

139       TBA
140
141
142
1430.9.8b                            2002-10-20                    OBJ_nid2obj(3)
Impressum