1X509_NAME_GET_INDEX_BY_NID(3)       OpenSSL      X509_NAME_GET_INDEX_BY_NID(3)
2
3
4

NAME

6       X509_NAME_get_index_by_NID, X509_NAME_get_index_by_OBJ,
7       X509_NAME_get_entry, X509_NAME_entry_count, X509_NAME_get_text_by_NID,
8       X509_NAME_get_text_by_OBJ - X509_NAME lookup and enumeration functions
9

SYNOPSIS

11        #include <openssl/x509.h>
12
13        int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos);
14        int X509_NAME_get_index_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, int lastpos);
15
16        int X509_NAME_entry_count(const X509_NAME *name);
17        X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, int loc);
18
19        int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len);
20        int X509_NAME_get_text_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, char *buf, int len);
21

DESCRIPTION

23       These functions allow an X509_NAME structure to be examined. The
24       X509_NAME structure is the same as the Name type defined in RFC2459
25       (and elsewhere) and used for example in certificate subject and issuer
26       names.
27
28       X509_NAME_get_index_by_NID() and X509_NAME_get_index_by_OBJ() retrieve
29       the next index matching nid or obj after lastpos. lastpos should
30       initially be set to -1. If there are no more entries -1 is returned.
31       If nid is invalid (doesn't correspond to a valid OID) then -2 is
32       returned.
33
34       X509_NAME_entry_count() returns the total number of entries in name.
35
36       X509_NAME_get_entry() retrieves the X509_NAME_ENTRY from name
37       corresponding to index loc. Acceptable values for loc run from 0 to
38       (X509_NAME_entry_count(name) - 1). The value returned is an internal
39       pointer which must not be freed.
40
41       X509_NAME_get_text_by_NID(), X509_NAME_get_text_by_OBJ() retrieve the
42       "text" from the first entry in name which matches nid or obj, if no
43       such entry exists -1 is returned. At most len bytes will be written and
44       the text written to buf will be null terminated. The length of the
45       output string written is returned excluding the terminating null. If
46       buf is <NULL> then the amount of space needed in buf (excluding the
47       final null) is returned.
48

NOTES

50       X509_NAME_get_text_by_NID() and X509_NAME_get_text_by_OBJ() should be
51       considered deprecated because they have various limitations which make
52       them of minimal use in practice. They can only find the first matching
53       entry and will copy the contents of the field verbatim: this can be
54       highly confusing if the target is a multicharacter string type like a
55       BMPString or a UTF8String.
56
57       For a more general solution X509_NAME_get_index_by_NID() or
58       X509_NAME_get_index_by_OBJ() should be used followed by
59       X509_NAME_get_entry() on any matching indices and then the various
60       X509_NAME_ENTRY utility functions on the result.
61
62       The list of all relevant NID_* and OBJ_* codes can be found in the
63       source code header files <openssl/obj_mac.h> and/or
64       <openssl/objects.h>.
65
66       Applications which could pass invalid NIDs to
67       X509_NAME_get_index_by_NID() should check for the return value of -2.
68       Alternatively the NID validity can be determined first by checking
69       OBJ_nid2obj(nid) is not NULL.
70

RETURN VALUES

72       X509_NAME_get_index_by_NID() and X509_NAME_get_index_by_OBJ() return
73       the index of the next matching entry or -1 if not found.
74       X509_NAME_get_index_by_NID() can also return -2 if the supplied NID is
75       invalid.
76
77       X509_NAME_entry_count() returns the total number of entries.
78
79       X509_NAME_get_entry() returns an X509_NAME pointer to the requested
80       entry or NULL if the index is invalid.
81

EXAMPLES

83       Process all entries:
84
85        int i;
86        X509_NAME_ENTRY *e;
87
88        for (i = 0; i < X509_NAME_entry_count(nm); i++) {
89            e = X509_NAME_get_entry(nm, i);
90            /* Do something with e */
91        }
92
93       Process all commonName entries:
94
95        int lastpos = -1;
96        X509_NAME_ENTRY *e;
97
98        for (;;) {
99            lastpos = X509_NAME_get_index_by_NID(nm, NID_commonName, lastpos);
100            if (lastpos == -1)
101                break;
102            e = X509_NAME_get_entry(nm, lastpos);
103            /* Do something with e */
104        }
105

SEE ALSO

107       ERR_get_error(3), d2i_X509_NAME(3)
108
110       Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.
111
112       Licensed under the OpenSSL license (the "License").  You may not use
113       this file except in compliance with the License.  You can obtain a copy
114       in the file LICENSE in the source distribution or at
115       <https://www.openssl.org/source/license.html>.
116
117
118
1191.1.1i                            2021-07-22     X509_NAME_GET_INDEX_BY_NID(3)
Impressum