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

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

<h1>X509_NAME_add_entry_by_txt(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="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#BUGS">BUGS</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>
X509_NAME_add_entry_by_txt, X509_NAME_add_entry_by_OBJ,
X509_NAME_add_entry_by_NID, X509_NAME_add_entry, X509_NAME_delete_entry -
X509_NAME modification functions

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/x509.h&gt;
</PRE>
<PRE> int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, const unsigned char *bytes, int len, int loc, int set);
</PRE>
<PRE> int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, unsigned char *bytes, int len, int loc, int set);
</PRE>
<PRE> int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, unsigned char *bytes, int len, int loc, int set);
</PRE>
<PRE> int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne, int loc, int set);
</PRE>
<PRE> X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>X509_NAME_add_entry_by_txt(),</CODE>
<CODE>X509_NAME_add_entry_by_OBJ()</CODE> and
<CODE>X509_NAME_add_entry_by_NID()</CODE> add a field whose name is defined
by a string <STRONG>field</STRONG>, an object <STRONG>obj</STRONG> or a NID <STRONG>nid</STRONG> respectively. The field value to be added is in <STRONG>bytes</STRONG> of length <STRONG>len</STRONG>. If
<STRONG>len</STRONG> is -1 then the field length is calculated internally using
<CODE>strlen(bytes).</CODE>

</P>
<P>
The type of field is determined by <STRONG>type</STRONG> which can either be a definition of the type of <STRONG>bytes</STRONG> (such as <STRONG>MBSTRING_ASC</STRONG>) or a standard ASN1 type (such as <STRONG>V_ASN1_IA5STRING</STRONG>). The new entry is added to a position determined by <STRONG>loc</STRONG> and <STRONG>set</STRONG>.

</P>
<P>
<CODE>X509_NAME_add_entry()</CODE> adds a copy of <STRONG>X509_NAME_ENTRY</STRONG> structure <STRONG>ne</STRONG>
to <STRONG>name</STRONG>. The new entry is added to a position determined by <STRONG>loc</STRONG>
and <STRONG>set</STRONG>. Since a copy of <STRONG>ne</STRONG> is added <STRONG>ne</STRONG> must be freed up after the call.

</P>
<P>
<CODE>X509_NAME_delete_entry()</CODE> deletes an entry from <STRONG>name</STRONG> at position
<STRONG>loc</STRONG>. The deleted entry is returned and must be freed up.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
The use of string types such as <STRONG>MBSTRING_ASC</STRONG> or <STRONG>MBSTRING_UTF8</STRONG>
is strongly recommened for the <STRONG>type</STRONG> parameter. This allows the internal code to correctly determine the type of
the field and to apply length checks according to the relevant standards.
This is done using <CODE>ASN1_STRING_set_by_NID().</CODE>

</P>
<P>
If instead an ASN1 type is used no checks are performed and the supplied
data in <STRONG>bytes</STRONG> is used directly.

</P>
<P>
In <CODE>X509_NAME_add_entry_by_txt()</CODE> the <STRONG>field</STRONG> string represents the field name using <CODE>OBJ_txt2obj(field,</CODE> 0).

</P>
<P>
The <STRONG>loc</STRONG> and <STRONG>set</STRONG> parameters determine where a new entry should be added. For almost all
applications <STRONG>loc</STRONG> can be set to -1 and <STRONG>set</STRONG>
to 0. This adds a new entry to the end of <STRONG>name</STRONG> as a single valued RelativeDistinguishedName (RDN).

</P>
<P>
<STRONG>loc</STRONG> actually determines the index where the new entry is inserted: if it is -1
it is appended. 

</P>
<P>
<STRONG>set</STRONG> determines how the new type is added. If it is zero a new RDN is created.

</P>
<P>
If <STRONG>set</STRONG> is -1 or 1 it is added to the previous or next RDN structure respectively.
This will then be a multivalued RDN: since multivalues RDNs are very seldom
used <STRONG>set</STRONG> is almost always set to zero.

</P>
<P>
<HR>
<H1><A NAME="EXAMPLES">EXAMPLES</A></H1>
<P>
Create an <STRONG>X509_NAME</STRONG> structure:

</P>
<P>
``C=UK, O=Disorganized Organization, CN=Joe Bloggs''

</P>
<PRE> X509_NAME *nm;
 nm = X509_NAME_new();
 if (nm == NULL)
        /* Some error */
 if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC,
                        &quot;C&quot;, &quot;UK&quot;, -1, -1, 0))
        /* Error */
 if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC,
                        &quot;O&quot;, &quot;Disorganized Organization&quot;, -1, -1, 0))
        /* Error */
 if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC,
                        &quot;CN&quot;, &quot;Joe Bloggs&quot;, -1, -1, 0))
        /* Error */
</PRE>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>X509_NAME_add_entry_by_txt(),</CODE>
<CODE>X509_NAME_add_entry_by_OBJ(),</CODE>
<CODE>X509_NAME_add_entry_by_NID()</CODE> and
<CODE>X509_NAME_add_entry()</CODE> return 1 for success of 0 if an error
occurred.

</P>
<P>
<CODE>X509_NAME_delete_entry()</CODE> returns either the deleted <STRONG>X509_NAME_ENTRY</STRONG>
structure of <STRONG>NULL</STRONG> if an error occurred.

</P>
<P>
<HR>
<H1><A NAME="BUGS">BUGS</A></H1>
<P>
<STRONG>type</STRONG> can still be set to <STRONG>V_ASN1_APP_CHOOSE</STRONG> to use a different algorithm to determine field types. Since this form does
not understand multicharacter types, performs no length checks and can
result in invalid field types its use is strongly discouraged.

</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>, <A HREF="../crypto/d2i_X509_NAME.html#">d2i_X509_NAME(3)</A>



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
:}


