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        #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        void OBJ_cleanup(void);
31

DESCRIPTION

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

NOTES

79       Objects in OpenSSL can have a short name, a long name and a numerical
80       identifier (NID) associated with them. A standard set of objects is
81       represented in an internal table. The appropriate values are defined in
82       the header file objects.h.
83
84       For example the OID for commonName has the following definitions:
85
86        #define SN_commonName                   "CN"
87        #define LN_commonName                   "commonName"
88        #define NID_commonName                  13
89
90       New objects can be added by calling OBJ_create().
91
92       Table objects have certain advantages over other objects: for example
93       their NIDs can be used in a C language switch statement. They are also
94       static constant structures which are shared: that is there is only a
95       single constant structure for each table object.
96
97       Objects which are not in the table have the NID value NID_undef.
98
99       Objects do not need to be in the internal tables to be processed, the
100       functions OBJ_txt2obj() and OBJ_obj2txt() can process the numerical
101       form of an OID.
102
103       Some objects are used to represent algorithms which do not have a
104       corresponding ASN.1 OBJECT IDENTIFIER encoding (for example no OID
105       currently exists for a particular algorithm). As a result they cannot
106       be encoded or decoded as part of ASN.1 structures. Applications can
107       determine if there is a corresponding OBJECT IDENTIFIER by checking
108       OBJ_length() is not zero.
109
110       These functions cannot return const because an ASN1_OBJECT can
111       represent both an internal, constant, OID and a dynamically-created
112       one.  The latter cannot be constant because it needs to be freed after
113       use.
114

EXAMPLES

116       Create an object for commonName:
117
118        ASN1_OBJECT *o;
119        o = OBJ_nid2obj(NID_commonName);
120
121       Check if an object is commonName
122
123        if (OBJ_obj2nid(obj) == NID_commonName)
124               /* Do something */
125
126       Create a new NID and initialize an object from it:
127
128        int new_nid;
129        ASN1_OBJECT *obj;
130
131        new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
132
133        obj = OBJ_nid2obj(new_nid);
134
135       Create a new object directly:
136
137        obj = OBJ_txt2obj("1.2.3.4", 1);
138

BUGS

140       OBJ_obj2txt() is awkward and messy to use: it doesn't follow the
141       convention of other OpenSSL functions where the buffer can be set to
142       NULL to determine the amount of data that should be written.  Instead
143       buf must point to a valid buffer and buf_len should be set to a
144       positive value. A buffer length of 80 should be more than enough to
145       handle any OID encountered in practice.
146

RETURN VALUES

148       OBJ_nid2obj() returns an ASN1_OBJECT structure or NULL is an error
149       occurred.  It returns a pointer to an internal table and does not
150       allocate memory; ASN1_OBJECT_free() will have no effect.
151
152       OBJ_nid2ln() and OBJ_nid2sn() returns a valid string or NULL on error.
153
154       OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() and OBJ_txt2nid() return a
155       NID or NID_undef on error.
156

SEE ALSO

158       ERR_get_error(3)
159

HISTORY

161       TBA
162
163
164
1651.0.2k                            2017-01-26                    OBJ_nid2obj(3)
Impressum