1X509_NAME_GET_INDEX_BY_NID(3ossl)   OpenSSL  X509_NAME_GET_INDEX_BY_NID(3ossl)
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(const X509_NAME *name, int nid, int lastpos);
14        int X509_NAME_get_index_by_OBJ(const X509_NAME *name,
15                                       const ASN1_OBJECT *obj, int lastpos);
16
17        int X509_NAME_entry_count(const X509_NAME *name);
18        X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, int loc);
19
20        int X509_NAME_get_text_by_NID(const X509_NAME *name, int nid,
21                                      char *buf, int len);
22        int X509_NAME_get_text_by_OBJ(const X509_NAME *name, const ASN1_OBJECT *obj,
23                                      char *buf, int len);
24

DESCRIPTION

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

NOTES

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

RETURN VALUES

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

EXAMPLES

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

SEE ALSO

111       ERR_get_error(3), d2i_X509_NAME(3)
112
114       Copyright 2002-2022 The OpenSSL Project Authors. All Rights Reserved.
115
116       Licensed under the Apache License 2.0 (the "License").  You may not use
117       this file except in compliance with the License.  You can obtain a copy
118       in the file LICENSE in the source distribution or at
119       <https://www.openssl.org/source/license.html>.
120
121
122
1233.1.1                             2023-08-31 X509_NAME_GET_INDEX_BY_NID(3ossl)
Impressum