xref: /openbsd-src/lib/libcrypto/man/d2i_ASN1_OBJECT.3 (revision c1a45aed656e7d5627c30c92421893a76f370ccb)
1.\" $OpenBSD: d2i_ASN1_OBJECT.3,v 1.12 2022/03/29 17:41:20 schwarze Exp $
2.\"
3.\" Copyright (c) 2017, 2022 Ingo Schwarze <schwarze@openbsd.org>
4.\"
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.
8.\"
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.
16.\"
17.Dd $Mdocdate: March 29 2022 $
18.Dt D2I_ASN1_OBJECT 3
19.Os
20.Sh NAME
21.Nm d2i_ASN1_OBJECT ,
22.Nm i2d_ASN1_OBJECT
23.\" c2i_ASN1_OBJECT is intentionally undocumented because it is unused
24.\" in real-world software and was removed from the OpenSSL 1.1.1 API
25.Nd decode and encode ASN.1 object identifiers
26.Sh SYNOPSIS
27.In openssl/asn1.h
28.Ft ASN1_OBJECT *
29.Fo d2i_ASN1_OBJECT
30.Fa "ASN1_OBJECT **val_out"
31.Fa "unsigned char **der_in"
32.Fa "long length"
33.Fc
34.Ft int
35.Fo i2d_ASN1_OBJECT
36.Fa "const ASN1_OBJECT *val_in"
37.Fa "unsigned char **der_out"
38.Fc
39.Sh DESCRIPTION
40These functions decode and encode ASN.1 object identifiers.
41For details about the semantics, examples, caveats, and bugs, see
42.Xr ASN1_item_d2i 3 .
43.Pp
44The LibreSSL implementation of
45.Fn d2i_ASN1_OBJECT
46always calls
47.Xr ASN1_OBJECT_free 3
48if an existing object is passed in via
49.Fa val_out
50and it always creates a new object from scratch.
51Other implementations may attempt to reuse an existing object,
52which is fragile and prone to bugs.
53Consequently, always passing
54.Dv NULL
55for the
56.Fa val_out
57argument is recommended.
58.Pp
59The objects returned from
60.Fn d2i_ASN1_OBJECT
61and the data contained in them are always marked as dynamically
62allocated, so when they are no longer needed,
63.Xr ASN1_OBJECT_free 3
64can be called on them.
65.Sh RETURN VALUES
66.Fn d2i_ASN1_OBJECT
67returns a pointer to the new
68.Vt ASN1_OBJECT
69object or
70.Dv NULL
71if an error occurs.
72With other implementations, it might return a pointer to the reused
73.Vt ASN1_OBJECT .
74.Pp
75.Fn i2d_ASN1_OBJECT
76returns the number of bytes successfully encoded
77or a value <= 0 if an error occurs.
78.Sh SEE ALSO
79.Xr a2d_ASN1_OBJECT 3 ,
80.Xr ASN1_item_d2i 3 ,
81.Xr ASN1_OBJECT_new 3 ,
82.Xr OBJ_nid2obj 3
83.Sh STANDARDS
84ITU-T Recommendation X.690, also known as ISO/IEC 8825-1:
85Information technology - ASN.1 encoding rules:
86Specification of Basic Encoding Rules (BER), Canonical Encoding
87Rules (CER) and Distinguished Encoding Rules (DER),
88section 8.19: Encoding of an object identifier value
89.Sh HISTORY
90.Fn d2i_ASN1_OBJECT
91and
92.Fn i2d_ASN1_OBJECT
93first appeared in SSLeay 0.5.1 and have been available since
94.Ox 2.4 .
95.Sh CAVEATS
96.Fn d2i_ASN1_OBJECT
97never sets the long and short names of the object, not even if the
98object identifier matches one that is built into the library.
99To find the names of an object identifier parsed from DER or BER
100input, call
101.Xr OBJ_obj2nid 3
102on the returned object, and then
103.Xr OBJ_nid2sn 3
104and
105.Xr OBJ_nid2ln 3
106on the result.
107