Blame doc/man3/X509_NAME_get_index_by_NID.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
X509_NAME_get_index_by_NID, X509_NAME_get_index_by_OBJ, X509_NAME_get_entry,
Packit c4476c
X509_NAME_entry_count, X509_NAME_get_text_by_NID, X509_NAME_get_text_by_OBJ -
Packit c4476c
X509_NAME lookup and enumeration functions
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/x509.h>
Packit c4476c
Packit c4476c
 int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos);
Packit c4476c
 int X509_NAME_get_index_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, int lastpos);
Packit c4476c
Packit c4476c
 int X509_NAME_entry_count(const X509_NAME *name);
Packit c4476c
 X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, int loc);
Packit c4476c
Packit c4476c
 int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len);
Packit c4476c
 int X509_NAME_get_text_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, char *buf, int len);
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
These functions allow an B<X509_NAME> structure to be examined. The
Packit c4476c
B<X509_NAME> structure is the same as the B<Name> type defined in
Packit c4476c
RFC2459 (and elsewhere) and used for example in certificate subject
Packit c4476c
and issuer names.
Packit c4476c
Packit c4476c
X509_NAME_get_index_by_NID() and X509_NAME_get_index_by_OBJ() retrieve
Packit c4476c
the next index matching B<nid> or B<obj> after B<lastpos>. B<lastpos>
Packit c4476c
should initially be set to -1. If there are no more entries -1 is returned.
Packit c4476c
If B<nid> is invalid (doesn't correspond to a valid OID) then -2 is returned.
Packit c4476c
Packit c4476c
X509_NAME_entry_count() returns the total number of entries in B<name>.
Packit c4476c
Packit c4476c
X509_NAME_get_entry() retrieves the B<X509_NAME_ENTRY> from B<name>
Packit c4476c
corresponding to index B<loc>. Acceptable values for B<loc> run from
Packit c4476c
0 to (X509_NAME_entry_count(name) - 1). The value returned is an
Packit c4476c
internal pointer which must not be freed.
Packit c4476c
Packit c4476c
X509_NAME_get_text_by_NID(), X509_NAME_get_text_by_OBJ() retrieve
Packit c4476c
the "text" from the first entry in B<name> which matches B<nid> or
Packit c4476c
B<obj>, if no such entry exists -1 is returned. At most B<len> bytes
Packit c4476c
will be written and the text written to B<buf> will be null
Packit c4476c
terminated. The length of the output string written is returned
Packit c4476c
excluding the terminating null. If B<buf> is <NULL> then the amount
Packit c4476c
of space needed in B<buf> (excluding the final null) is returned.
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
X509_NAME_get_text_by_NID() and X509_NAME_get_text_by_OBJ() should be
Packit c4476c
considered deprecated because they
Packit c4476c
have various limitations which make them
Packit c4476c
of minimal use in practice. They can only find the first matching
Packit c4476c
entry and will copy the contents of the field verbatim: this can
Packit c4476c
be highly confusing if the target is a multicharacter string type
Packit c4476c
like a BMPString or a UTF8String.
Packit c4476c
Packit c4476c
For a more general solution X509_NAME_get_index_by_NID() or
Packit c4476c
X509_NAME_get_index_by_OBJ() should be used followed by
Packit c4476c
X509_NAME_get_entry() on any matching indices and then the
Packit c4476c
various B<X509_NAME_ENTRY> utility functions on the result.
Packit c4476c
Packit c4476c
The list of all relevant B<NID_*> and B<OBJ_* codes> can be found in
Packit c4476c
the source code header files E<lt>openssl/obj_mac.hE<gt> and/or
Packit c4476c
E<lt>openssl/objects.hE<gt>.
Packit c4476c
Packit c4476c
Applications which could pass invalid NIDs to X509_NAME_get_index_by_NID()
Packit c4476c
should check for the return value of -2. Alternatively the NID validity
Packit c4476c
can be determined first by checking OBJ_nid2obj(nid) is not NULL.
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
X509_NAME_get_index_by_NID() and X509_NAME_get_index_by_OBJ()
Packit c4476c
return the index of the next matching entry or -1 if not found.
Packit c4476c
X509_NAME_get_index_by_NID() can also return -2 if the supplied
Packit c4476c
NID is invalid.
Packit c4476c
Packit c4476c
X509_NAME_entry_count() returns the total number of entries.
Packit c4476c
Packit c4476c
X509_NAME_get_entry() returns an B<X509_NAME> pointer to the
Packit c4476c
requested entry or B<NULL> if the index is invalid.
Packit c4476c
Packit c4476c
=head1 EXAMPLES
Packit c4476c
Packit c4476c
Process all entries:
Packit c4476c
Packit c4476c
 int i;
Packit c4476c
 X509_NAME_ENTRY *e;
Packit c4476c
Packit c4476c
 for (i = 0; i < X509_NAME_entry_count(nm); i++) {
Packit c4476c
     e = X509_NAME_get_entry(nm, i);
Packit c4476c
     /* Do something with e */
Packit c4476c
 }
Packit c4476c
Packit c4476c
Process all commonName entries:
Packit c4476c
Packit c4476c
 int lastpos = -1;
Packit c4476c
 X509_NAME_ENTRY *e;
Packit c4476c
Packit c4476c
 for (;;) {
Packit c4476c
     lastpos = X509_NAME_get_index_by_NID(nm, NID_commonName, lastpos);
Packit c4476c
     if (lastpos == -1)
Packit c4476c
         break;
Packit c4476c
     e = X509_NAME_get_entry(nm, lastpos);
Packit c4476c
     /* Do something with e */
Packit c4476c
 }
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<ERR_get_error(3)>, L<d2i_X509_NAME(3)>
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut