1 .\" $OpenBSD: d2i_ASN1_OCTET_STRING.3,v 1.5 2017/08/01 14:57:03 schwarze Exp $
3 .\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
5 .\" Permission to use, copy, modify, and distribute this software for any
6 .\" purpose with or without fee is hereby granted, provided that the above
7 .\" copyright notice and this permission notice appear in all copies.
9 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 .Dd $Mdocdate: August 1 2017 $
18 .Dt D2I_ASN1_OCTET_STRING 3
21 .Nm d2i_ASN1_OCTET_STRING ,
22 .Nm i2d_ASN1_OCTET_STRING ,
23 .Nm d2i_ASN1_BIT_STRING ,
24 .Nm i2d_ASN1_BIT_STRING ,
25 .Nm d2i_ASN1_INTEGER ,
26 .Nm i2d_ASN1_INTEGER ,
27 .Nm d2i_ASN1_UINTEGER ,
28 .Nm d2i_ASN1_ENUMERATED ,
29 .Nm i2d_ASN1_ENUMERATED ,
30 .Nm d2i_ASN1_UTF8STRING ,
31 .Nm i2d_ASN1_UTF8STRING ,
32 .Nm d2i_ASN1_IA5STRING ,
33 .Nm i2d_ASN1_IA5STRING ,
34 .Nm d2i_ASN1_UNIVERSALSTRING ,
35 .Nm i2d_ASN1_UNIVERSALSTRING ,
36 .Nm d2i_ASN1_BMPSTRING ,
37 .Nm i2d_ASN1_BMPSTRING ,
38 .Nm d2i_ASN1_GENERALSTRING ,
39 .Nm i2d_ASN1_GENERALSTRING ,
40 .Nm d2i_ASN1_T61STRING ,
41 .Nm i2d_ASN1_T61STRING ,
42 .Nm d2i_ASN1_VISIBLESTRING ,
43 .Nm i2d_ASN1_VISIBLESTRING ,
44 .Nm d2i_ASN1_PRINTABLESTRING ,
45 .Nm i2d_ASN1_PRINTABLESTRING ,
46 .Nm d2i_ASN1_PRINTABLE ,
47 .Nm i2d_ASN1_PRINTABLE ,
48 .Nm d2i_DIRECTORYSTRING ,
49 .Nm i2d_DIRECTORYSTRING ,
52 .Nm d2i_ASN1_GENERALIZEDTIME ,
53 .Nm i2d_ASN1_GENERALIZEDTIME ,
54 .Nm d2i_ASN1_UTCTIME ,
55 .Nm i2d_ASN1_UTCTIME ,
58 .Nd decode and encode ASN1_STRING objects
61 .Ft ASN1_OCTET_STRING *
62 .Fo d2i_ASN1_OCTET_STRING
63 .Fa "ASN1_OCTET_STRING **val_out"
64 .Fa "const unsigned char **der_in"
68 .Fo i2d_ASN1_OCTET_STRING
69 .Fa "ASN1_OCTET_STRING *val_in"
70 .Fa "unsigned char **der_out"
73 .Fo d2i_ASN1_BIT_STRING
74 .Fa "ASN1_BIT_STRING **val_out"
75 .Fa "const unsigned char **der_in"
79 .Fo i2d_ASN1_BIT_STRING
80 .Fa "ASN1_BIT_STRING *val_in"
81 .Fa "unsigned char **der_out"
85 .Fa "ASN1_INTEGER **val_out"
86 .Fa "const unsigned char **der_in"
91 .Fa "ASN1_INTEGER *val_in"
92 .Fa "unsigned char **der_out"
96 .Fa "ASN1_INTEGER **val_out"
97 .Fa "const unsigned char **der_in"
100 .Ft ASN1_ENUMERATED *
101 .Fo d2i_ASN1_ENUMERATED
102 .Fa "ASN1_ENUMERATED **val_out"
103 .Fa "const unsigned char **der_in"
107 .Fo i2d_ASN1_ENUMERATED
108 .Fa "ASN1_ENUMERATED *val_in"
109 .Fa "unsigned char **der_out"
111 .Ft ASN1_UTF8STRING *
112 .Fo d2i_ASN1_UTF8STRING
113 .Fa "ASN1_UTF8STRING **val_out"
114 .Fa "const unsigned char **der_in"
118 .Fo i2d_ASN1_UTF8STRING
119 .Fa "ASN1_UTF8STRING *val_in"
120 .Fa "unsigned char **der_out"
123 .Fo d2i_ASN1_IA5STRING
124 .Fa "ASN1_IA5STRING **val_out"
125 .Fa "const unsigned char **der_in"
129 .Fo i2d_ASN1_IA5STRING
130 .Fa "ASN1_IA5STRING *val_in"
131 .Fa "unsigned char **der_out"
133 .Ft ASN1_UNIVERSALSTRING *
134 .Fo d2i_ASN1_UNIVERSALSTRING
135 .Fa "ASN1_UNIVERSALSTRING **val_out"
136 .Fa "const unsigned char **der_in"
140 .Fo i2d_ASN1_UNIVERSALSTRING
141 .Fa "ASN1_UNIVERSALSTRING *val_in"
142 .Fa "unsigned char **der_out"
145 .Fo d2i_ASN1_BMPSTRING
146 .Fa "ASN1_BMPSTRING **val_out"
147 .Fa "const unsigned char **der_in"
151 .Fo i2d_ASN1_BMPSTRING
152 .Fa "ASN1_BMPSTRING *val_in"
153 .Fa "unsigned char **der_out"
155 .Ft ASN1_GENERALSTRING *
156 .Fo d2i_ASN1_GENERALSTRING
157 .Fa "ASN1_GENERALSTRING **val_out"
158 .Fa "const unsigned char **der_in"
162 .Fo i2d_ASN1_GENERALSTRING
163 .Fa "ASN1_GENERALSTRING *val_in"
164 .Fa "unsigned char **der_out"
167 .Fo d2i_ASN1_T61STRING
168 .Fa "ASN1_T61STRING **val_out"
169 .Fa "const unsigned char **der_in"
173 .Fo i2d_ASN1_T61STRING
174 .Fa "ASN1_T61STRING *val_in"
175 .Fa "unsigned char **der_out"
177 .Ft ASN1_VISIBLESTRING *
178 .Fo d2i_ASN1_VISIBLESTRING
179 .Fa "ASN1_VISIBLESTRING **val_out"
180 .Fa "const unsigned char **der_in"
184 .Fo i2d_ASN1_VISIBLESTRING
185 .Fa "ASN1_VISIBLESTRING *val_in"
186 .Fa "unsigned char **der_out"
188 .Ft ASN1_PRINTABLESTRING *
189 .Fo d2i_ASN1_PRINTABLESTRING
190 .Fa "ASN1_PRINTABLESTRING **val_out"
191 .Fa "const unsigned char **der_in"
195 .Fo i2d_ASN1_PRINTABLESTRING
196 .Fa "ASN1_PRINTABLESTRING *val_in"
197 .Fa "unsigned char **der_out"
200 .Fo d2i_ASN1_PRINTABLE
201 .Fa "ASN1_STRING **val_out"
202 .Fa "const unsigned char **der_in"
206 .Fo i2d_ASN1_PRINTABLE
207 .Fa "ASN1_STRING *val_in"
208 .Fa "unsigned char **der_out"
211 .Fo d2i_DIRECTORYSTRING
212 .Fa "ASN1_STRING **val_out"
213 .Fa "const unsigned char **der_in"
217 .Fo i2d_DIRECTORYSTRING
218 .Fa "ASN1_STRING *val_in"
219 .Fa "unsigned char **der_out"
223 .Fa "ASN1_STRING **val_out"
224 .Fa "const unsigned char **der_in"
229 .Fa "ASN1_STRING *val_in"
230 .Fa "unsigned char **der_out"
232 .Ft ASN1_GENERALIZEDTIME *
233 .Fo d2i_ASN1_GENERALIZEDTIME
234 .Fa "ASN1_GENERALIZEDTIME **val_out"
235 .Fa "const unsigned char **der_in"
239 .Fo i2d_ASN1_GENERALIZEDTIME
240 .Fa "ASN1_GENERALIZEDTIME *val_in"
241 .Fa "unsigned char **der_out"
245 .Fa "ASN1_UTCTIME **val_out"
246 .Fa "const unsigned char **der_in"
251 .Fa "ASN1_UTCTIME *val_in"
252 .Fa "unsigned char **der_out"
256 .Fa "ASN1_TIME **val_out"
257 .Fa "const unsigned char **der_in"
262 .Fa "ASN1_TIME *val_in"
263 .Fa "unsigned char **der_out"
266 These functions decode and encode various ASN.1 built-in types
267 that can be represented by
270 For details about the semantics, examples, caveats, and bugs, see
271 .Xr ASN1_item_d2i 3 .
273 The format consists of one identifier octet,
274 one or more length octets,
275 and one or more content octets.
276 The identifier octets and corresponding ASN.1 types are as follows:
277 .Bl -column ASN1_GENERALIZEDTIME identifier
278 .It Em OpenSSL type Ta Em identifier Ta Em ASN.1 type
280 .It Vt ASN1_OCTET_STRING Ta 0x04 Ta OCTET STRING
281 .It Vt ASN1_BIT_STRING Ta 0x03 Ta BIT STRING
282 .It Vt ASN1_INTEGER Ta 0x02 Ta INTEGER
283 .It Vt ASN1_ENUMERATED Ta 0x0a Ta ENUMERATED
284 .It Vt ASN1_UTF8STRING Ta 0x0c Ta UTF8String
285 .It Vt ASN1_IA5STRING Ta 0x16 Ta IA5String
286 .It Vt ASN1_UNIVERSALSTRING Ta 0x1c Ta UniversalString
287 .It Vt ASN1_BMPSTRING Ta 0x1e Ta BMPString
288 .It Vt ASN1_GENERALSTRING Ta 0x1b Ta GeneralString
289 .It Vt ASN1_T61STRING Ta 0x14 Ta T61String
290 .It Vt ASN1_VISIBLESTRING Ta 0x1a Ta VisibleString
291 .It Vt ASN1_PRINTABLESTRING Ta 0x13 Ta PrintableString
292 .It Vt ASN1_GENERALIZEDTIME Ta 0x18 Ta GeneralizedTime
293 .It Vt ASN1_UTCTIME Ta 0x17 Ta UTCTime
296 .Fn d2i_DIRECTORYSTRING
298 .Fn i2d_DIRECTORYSTRING
299 decode and encode an ASN.1
301 structure defined in RFC 5280 section 4.1.2.4
305 .Xr EDIPARTYNAME_new 3 .
306 When decoding, it accepts any of the types UTF8String, UniversalString,
307 BMPString, T61String, or PrintableString.
309 it writes out the character string type that is actually passed in.
311 .Fn d2i_ASN1_PRINTABLE
313 .Fn i2d_ASN1_PRINTABLE
314 are non-standard variants of
315 .Fn d2i_DIRECTORYSTRING
317 .Fn i2d_DIRECTORYSTRING
318 that also accept IA5String, NumericString, BIT STRING, and SEQUENCE
319 ASN.1 values as well as ASN.1 values with unknown identifier
320 octets (0x07, 0x08, 0x09, 0x0b, 0x0d, 0x0e, 0x0f, 0x1d, and 0x1f).
321 Even though the standard requires the use of
323 in the relative distinguished names described in
324 .Xr X509_NAME_ENTRY_new 3 ,
325 the library accepts this wider range of choices.
330 decode and encode an ASN.1
332 structure defined in RFC 5280 section 4.2.1.4
335 structures in certificate policies; see
336 .Xr USERNOTICE_new 3 .
337 When decoding, it accepts any of the types UTF8String, IA5String,
338 BMPString, or VisibleString.
340 it writes out the character string type that is actually passed in.
345 decode and encode an ASN.1
347 structure defined in RFC 5280 section 4.1
350 structures in certificates; see
352 They are also used for certificate revocation lists; see
353 .Xr X509_CRL_INFO_new 3 .
354 When decoding, it accepts either GeneralizedTime or UTCTime.
355 When encoding, it writes out the time type that is actually passed in.
357 .Fn d2i_ASN1_UINTEGER
360 except that it ignores the sign bit in the BER encoding and treats
361 all integers as positive.
362 It helps to process BER input produced by broken software
363 that neglects adding a leading NUL content byte where required.
367 decoding functions return an
375 encoding functions return the number of bytes successfully encoded
376 or a negative value if an error occurs.
378 .Xr ASN1_item_d2i 3 ,
379 .Xr ASN1_STRING_new 3
381 ITU-T Recommendation X.680, also known as ISO/IEC 8824-1:
382 Information technology - Abstract Syntax Notation One (ASN.1):
383 Specification of basic notation
385 RFC 5280: Internet X.509 Public Key Infrastructure Certificate and
386 Certificate Revocation List (CRL) Profile