
#use wml::openssl-macros area=docs page=OBJ_nid2obj

<title>Documents, OBJ_nid2obj(3)</title>

<h1>OBJ_nid2obj(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#NOTES">NOTES</A>
	<LI><A HREF="#EXAMPLES">EXAMPLES</A>
	<LI><A HREF="#BUGS">BUGS</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
	<LI><A HREF="#HISTORY">HISTORY</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
OBJ_nid2obj, OBJ_nid2ln, OBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid, OBJ_ln2nid,
OBJ_sn2nid, OBJ_cmp, OBJ_dup, OBJ_txt2obj, OBJ_obj2txt, OBJ_create,
OBJ_cleanup - ASN1 object utility functions

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/objects.h&gt;
</PRE>
<PRE> ASN1_OBJECT * OBJ_nid2obj(int n);
 const char *  OBJ_nid2ln(int n);
 const char *  OBJ_nid2sn(int n);
</PRE>
<PRE> int OBJ_obj2nid(const ASN1_OBJECT *o);
 int OBJ_ln2nid(const char *ln);
 int OBJ_sn2nid(const char *sn);
</PRE>
<PRE> int OBJ_txt2nid(const char *s);
</PRE>
<PRE> ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name);
 int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name);
</PRE>
<PRE> int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);
 ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o);
</PRE>
<PRE> int OBJ_create(const char *oid,const char *sn,const char *ln);
 void OBJ_cleanup(void);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
The ASN1 object utility functions process ASN1_OBJECT structures which are
a representation of the ASN1 OBJECT IDENTIFIER (OID) type.

</P>
<P>
<CODE>OBJ_nid2obj(),</CODE> <CODE>OBJ_nid2ln()</CODE> and
<CODE>OBJ_nid2sn()</CODE> convert the NID <STRONG>n</STRONG> to an ASN1_OBJECT structure, its long name and its short name respectively,
or <STRONG>NULL</STRONG> is an error occurred.

</P>
<P>
<CODE>OBJ_obj2nid(),</CODE> <CODE>OBJ_ln2nid(),</CODE>
<CODE>OBJ_sn2nid()</CODE> return the corresponding NID for the object <STRONG>o</STRONG>, the long name &lt;ln&gt; or the short name &lt;sn&gt; respectively or
NID_undef if an error occurred.

</P>
<P>
<CODE>OBJ_txt2nid()</CODE> returns NID corresponding to text string &lt;s&gt;. <STRONG>s</STRONG> can be a long name, a short name or the numerical respresentation of an
object.

</P>
<P>
<CODE>OBJ_txt2obj()</CODE> converts the text string <STRONG>s</STRONG> into an ASN1_OBJECT structure. If <STRONG>no_name</STRONG> is 0 then long names and short names will be interpreted as well as
numerical forms. If <STRONG>no_name</STRONG> is 1 only the numerical form is acceptable.

</P>
<P>
<CODE>OBJ_obj2txt()</CODE> converts the <STRONG>ASN1_OBJECT</STRONG>  <STRONG>a</STRONG> into a textual representation. The representation is written as a null
terminated string to <STRONG>buf</STRONG>
at most <STRONG>buf_len</STRONG> bytes are written, truncating the result if necessary. The total amount of
space required is returned. If <STRONG>no_name</STRONG> is 0 then if the object has a long or short name then that will be used,
otherwise the numerical form will be used. If <STRONG>no_name</STRONG> is 1 then the numerical form will always be used.

</P>
<P>
<CODE>OBJ_cmp()</CODE> compares <STRONG>a</STRONG> to <STRONG>b</STRONG>. If the two are identical 0 is returned.

</P>
<P>
<CODE>OBJ_dup()</CODE> returns a copy of <STRONG>o</STRONG>.

</P>
<P>
<CODE>OBJ_create()</CODE> adds a new object to the internal table. <STRONG>oid</STRONG> is the numerical form of the object, <STRONG>sn</STRONG> the short name and <STRONG>ln</STRONG> the long name. A new NID is returned for the created object.

</P>
<P>
<CODE>OBJ_cleanup()</CODE> cleans up OpenSSLs internal object table: this
should be called before an application exits if any new objects were added
using <CODE>OBJ_create().</CODE>

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
Objects in OpenSSL can have a short name, a long name and a numerical
identifier (NID) associated with them. A standard set of objects is
represented in an internal table. The appropriate values are defined in the
header file <STRONG>objects.h</STRONG>.

</P>
<P>
For example the OID for commonName has the following definitions:

</P>
<PRE> #define SN_commonName                   &quot;CN&quot;
 \#define LN_commonName                   &quot;commonName&quot;
 \#define NID_commonName                  13
</PRE>
<P>
New objects can be added by calling <CODE>OBJ_create().</CODE>

</P>
<P>
Table objects have certain advantages over other objects: for example their
NIDs can be used in a C language switch statement. They are also static
constant structures which are shared: that is there is only a single
constant structure for each table object.

</P>
<P>
Objects which are not in the table have the NID value NID_undef.

</P>
<P>
Objects do not need to be in the internal tables to be processed, the
functions <CODE>OBJ_txt2obj()</CODE> and <CODE>OBJ_obj2txt()</CODE> can
process the numerical form of an OID.

</P>
<P>
<HR>
<H1><A NAME="EXAMPLES">EXAMPLES</A></H1>
<P>
Create an object for <STRONG>commonName</STRONG>:

</P>
<PRE> ASN1_OBJECT *o;
 o = OBJ_nid2obj(NID_commonName);
</PRE>
<P>
Check if an object is <STRONG>commonName</STRONG>



</P>
<PRE> if (OBJ_obj2nid(obj) == NID_commonName)
        /* Do something */
</PRE>
<P>
Create a new NID and initialize an object from it:

</P>
<PRE> int new_nid;
 ASN1_OBJECT *obj;
 new_nid = OBJ_create(&quot;1.2.3.4&quot;, &quot;NewOID&quot;, &quot;New Object Identifier&quot;);
</PRE>
<PRE> obj = OBJ_nid2obj(new_nid);
 
Create a new object directly:
</PRE>
<PRE> obj = OBJ_txt2obj(&quot;1.2.3.4&quot;, 1);
</PRE>
<P>
<HR>
<H1><A NAME="BUGS">BUGS</A></H1>
<P>
<CODE>OBJ_obj2txt()</CODE> is awkward and messy to use: it doesn't follow
the convention of other OpenSSL functions where the buffer can be set to <STRONG>NULL</STRONG> to determine the amount of data that should be written. Instead <STRONG>buf</STRONG> must point to a valid buffer and <STRONG>buf_len</STRONG> should be set to a positive value. A buffer length of 80 should be more
than enough to handle any OID encountered in practice.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>OBJ_nid2obj()</CODE> returns an <STRONG>ASN1_OBJECT</STRONG> structure or <STRONG>NULL</STRONG> is an error occurred.

</P>
<P>
<CODE>OBJ_nid2ln()</CODE> and <CODE>OBJ_nid2sn()</CODE> returns a valid
string or <STRONG>NULL</STRONG>
on error.

</P>
<P>
<CODE>OBJ_obj2nid(),</CODE> <CODE>OBJ_ln2nid(),</CODE>
<CODE>OBJ_sn2nid()</CODE> and <CODE>OBJ_txt2nid()</CODE> return a NID or <STRONG>NID_undef</STRONG> on error.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A>



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
TBA

</P>
:}


