summaryrefslogtreecommitdiff
path: root/static/netbsd/man3/X509_NAME_get_index_by_NID.3
blob: 361255cce798cc0bb6c38617d03dfac0590d2fbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
.\"	$NetBSD: X509_NAME_get_index_by_NID.3,v 1.5 2026/04/08 17:06:49 christos Exp $
.\"
.\" -*- mode: troff; coding: utf-8 -*-
.\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
.ie n \{\
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
.    if \nF \{\
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{\
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\"
.\" Required to disable full justification in groff 1.23.0.
.if n .ds AD l
.\" ========================================================================
.\"
.IX Title "X509_NAME_get_index_by_NID 3"
.TH X509_NAME_get_index_by_NID 3 2026-04-07 3.5.6 OpenSSL
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH NAME
X509_NAME_get_index_by_NID, X509_NAME_get_index_by_OBJ, X509_NAME_get_entry,
X509_NAME_entry_count, X509_NAME_get_text_by_NID, X509_NAME_get_text_by_OBJ \-
X509_NAME lookup and enumeration functions
.SH SYNOPSIS
.IX Header "SYNOPSIS"
.Vb 1
\& #include <openssl/x509.h>
\&
\& int X509_NAME_get_index_by_NID(const X509_NAME *name, int nid, int lastpos);
\& int X509_NAME_get_index_by_OBJ(const X509_NAME *name,
\&                                const ASN1_OBJECT *obj, int lastpos);
\&
\& int X509_NAME_entry_count(const X509_NAME *name);
\& X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, int loc);
\&
\& int X509_NAME_get_text_by_NID(const X509_NAME *name, int nid,
\&                               char *buf, int len);
\& int X509_NAME_get_text_by_OBJ(const X509_NAME *name, const ASN1_OBJECT *obj,
\&                               char *buf, int len);
.Ve
.SH DESCRIPTION
.IX Header "DESCRIPTION"
These functions allow an \fBX509_NAME\fR structure to be examined. The
\&\fBX509_NAME\fR structure is the same as the \fBName\fR type defined in
RFC2459 (and elsewhere) and used for example in certificate subject
and issuer names.
.PP
\&\fBX509_NAME_get_index_by_NID()\fR and \fBX509_NAME_get_index_by_OBJ()\fR retrieve
the next index matching \fBnid\fR or \fBobj\fR after \fBlastpos\fR. \fBlastpos\fR
should initially be set to \-1. If there are no more entries \-1 is returned.
If \fBnid\fR is invalid (doesn\*(Aqt correspond to a valid OID) then \-2 is returned.
.PP
\&\fBX509_NAME_entry_count()\fR returns the total number of entries in \fBname\fR.
.PP
\&\fBX509_NAME_get_entry()\fR retrieves the \fBX509_NAME_ENTRY\fR from \fBname\fR
corresponding to index \fBloc\fR. Acceptable values for \fBloc\fR run from
0 to (X509_NAME_entry_count(name) \- 1). The value returned is an
internal pointer which must not be freed.
.PP
\&\fBX509_NAME_get_text_by_NID()\fR, \fBX509_NAME_get_text_by_OBJ()\fR retrieve
the "text" from the first entry in \fBname\fR which matches \fBnid\fR or
\&\fBobj\fR, if no such entry exists \-1 is returned. At most \fBlen\fR bytes
will be written and the text written to \fBbuf\fR will be null
terminated. The length of the output string written is returned
excluding the terminating null. If \fBbuf\fR is <NULL> then the amount
of space needed in \fBbuf\fR (excluding the final null) is returned.
.SH NOTES
.IX Header "NOTES"
\&\fBX509_NAME_get_text_by_NID()\fR and \fBX509_NAME_get_text_by_OBJ()\fR should be
considered deprecated because they
have various limitations which make them
of minimal use in practice. They can only find the first matching
entry and will copy the contents of the field verbatim: this can
be highly confusing if the target is a multicharacter string type
like a BMPString or a UTF8String.
.PP
For a more general solution \fBX509_NAME_get_index_by_NID()\fR or
\&\fBX509_NAME_get_index_by_OBJ()\fR should be used followed by
\&\fBX509_NAME_get_entry()\fR on any matching indices and then the
various \fBX509_NAME_ENTRY\fR utility functions on the result.
.PP
The list of all relevant \fBNID_*\fR and \fBOBJ_* codes\fR can be found in
the source code header files \fI<openssl/obj_mac.h>\fR and/or
\&\fI<openssl/objects.h>\fR.
.PP
Applications which could pass invalid NIDs to \fBX509_NAME_get_index_by_NID()\fR
should check for the return value of \-2. Alternatively the NID validity
can be determined first by checking OBJ_nid2obj(nid) is not NULL.
.SH "RETURN VALUES"
.IX Header "RETURN VALUES"
\&\fBX509_NAME_get_index_by_NID()\fR and \fBX509_NAME_get_index_by_OBJ()\fR
return the index of the next matching entry or \-1 if not found.
\&\fBX509_NAME_get_index_by_NID()\fR can also return \-2 if the supplied
NID is invalid.
.PP
\&\fBX509_NAME_entry_count()\fR returns the total number of entries, and 0
for failure.
.PP
\&\fBX509_NAME_get_entry()\fR returns an \fBX509_NAME\fR pointer to the
requested entry or \fBNULL\fR if the index is invalid.
.SH EXAMPLES
.IX Header "EXAMPLES"
Process all entries:
.PP
.Vb 2
\& int i;
\& X509_NAME_ENTRY *e;
\&
\& for (i = 0; i < X509_NAME_entry_count(nm); i++) {
\&     e = X509_NAME_get_entry(nm, i);
\&     /* Do something with e */
\& }
.Ve
.PP
Process all commonName entries:
.PP
.Vb 2
\& int lastpos = \-1;
\& X509_NAME_ENTRY *e;
\&
\& for (;;) {
\&     lastpos = X509_NAME_get_index_by_NID(nm, NID_commonName, lastpos);
\&     if (lastpos == \-1)
\&         break;
\&     e = X509_NAME_get_entry(nm, lastpos);
\&     /* Do something with e */
\& }
.Ve
.SH "SEE ALSO"
.IX Header "SEE ALSO"
\&\fBERR_get_error\fR\|(3), \fBd2i_X509_NAME\fR\|(3)
.SH COPYRIGHT
.IX Header "COPYRIGHT"
Copyright 2002\-2021 The OpenSSL Project Authors. All Rights Reserved.
.PP
Licensed under the Apache License 2.0 (the "License").  You may not use
this file except in compliance with the License.  You can obtain a copy
in the file LICENSE in the source distribution or at
<https://www.openssl.org/source/license.html>.