summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-04-20 16:15:29 +0000
committertb <>2023-04-20 16:15:29 +0000
commitc4b22405d730006befe5f8dfeb5f0bd1bd35255a (patch)
tree999afb33516e2b8ee0feee0a0a284cee27a52598 /src/lib
parent88cad374cc9df3202c8725ab01d3afbec20e6e83 (diff)
downloadopenbsd-c4b22405d730006befe5f8dfeb5f0bd1bd35255a.tar.gz
openbsd-c4b22405d730006befe5f8dfeb5f0bd1bd35255a.tar.bz2
openbsd-c4b22405d730006befe5f8dfeb5f0bd1bd35255a.zip
Add documentation for s2i_ASN1_INTEGER and related functions
These functions convert strings to internal objects and vice versa. This is a best effort, probably with a lot of room for improvement, which can happen in tree if anyone cares. It's better than nothing. Nothing in turn would be significantly better than the utter garbage a related project has managed to land as part of their efforts towards significant documentation improvements in a recent major relase. This leaves a dangling reference to the misnamed X509V3_METHOD_get_nid(3) which I may or may not fill in the future. I am unsure about the HISTORY section's precision, but that's what I got from cvs history. All these functions are about a quarter century old (and it shows), so I don't think it matters very much.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/man/s2i_ASN1_INTEGER.3195
1 files changed, 195 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/s2i_ASN1_INTEGER.3 b/src/lib/libcrypto/man/s2i_ASN1_INTEGER.3
new file mode 100644
index 0000000000..83633d684b
--- /dev/null
+++ b/src/lib/libcrypto/man/s2i_ASN1_INTEGER.3
@@ -0,0 +1,195 @@
1.\" $OpenBSD: s2i_ASN1_INTEGER.3,v 1.1 2023/04/20 16:15:29 tb Exp $
2.\"
3.\" Copyright (c) 2023 Theo Buehler <tb@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: April 20 2023 $
18.Dt I2S_ASN1_ENUMERATED 3
19.Os
20.Sh NAME
21.Nm i2s_ASN1_ENUMERATED ,
22.Nm i2s_ASN1_ENUMERATED_TABLE ,
23.Nm i2s_ASN1_INTEGER ,
24.Nm s2i_ASN1_INTEGER ,
25.Nm i2s_ASN1_OCTET_STRING ,
26.Nm s2i_ASN1_OCTET_STRING
27.Nd ASN.1 data type conversion utilities for certificate extensions
28.Sh SYNOPSIS
29.In openssl/asn1.h
30.In openssl/x509v3.h
31.Ft "char *"
32.Fo i2s_ASN1_ENUMERATED
33.Fa "X509V3_EXT_METHOD *method"
34.Fa "const ASN1_ENUMERATED *a"
35.Fc
36.Ft "char *"
37.Fo i2s_ASN1_INTEGER
38.Fa "X509V3_EXT_METHOD *method"
39.Fa "const ASN1_INTEGER *a"
40.Fc
41.Ft "ASN1_INTEGER *"
42.Fo s2i_ASN1_INTEGER
43.Fa "X509V3_EXT_METHOD *method"
44.Fa "const char *value"
45.Fc
46.Ft "char *"
47.Fo i2s_ASN1_OCTET_STRING
48.Fa "X509V3_EXT_METHOD *method"
49.Fa "const ASN1_OCTET_STRING *aos"
50.Fc
51.Ft "ASN1_OCTET_STRING *"
52.Fo s2i_ASN1_OCTET_STRING
53.Fa "X509V3_EXT_METHOD *method"
54.Fa "X509V3_CTX *ctx"
55.Fa "const char *value"
56.Fc
57.Ft "char *"
58.Fo i2s_ASN1_ENUMERATED_TABLE
59.Fa "X509V3_EXT_METHOD *method"
60.Fa "const ASN1_ENUMERATED *aenum"
61.Fc
62.Sh DESCRIPTION
63These functions convert to and from
64.Vt ASN1_ENUMERATED ,
65.Vt ASN1_INTEGER ,
66and
67.Vt ASN1_OCTET_STRING
68objects.
69They are primarily used internally for parsing configuration files and
70displaying of X.509v3 certificate extensions.
71With the exception of
72.Fn i2s_ASN1_ENUMERATED_TABLE ,
73these functions ignore the
74.Fa method
75argument.
76Any object or string returned by these functions must be freed by the caller.
77.Pp
78.Fn i2s_ASN1_ENUMERATED
79and
80.Fn i2s_ASN1_INTEGER
81first convert
82.Fa a
83into a
84.Vt BIGNUM
85object with
86.Xr ASN1_ENUMERATED_to_BN 3
87or
88.Xr ASN1_INTEGER_to_BN 3
89and then derive a string representation using
90.Xr BN_bn2dec 3
91or
92.Xr BN_bn2hex 3 .
93Decimal representation is used if the number has less than 128 bits,
94otherwise hexadecimal representation is used to avoid excessive conversion cost.
95.Pp
96.Fn s2i_ASN1_INTEGER
97converts a NUL-terminated decimal or hexadecimal string representation of
98an integer into an
99.Vt ASN1_INTEGER
100object.
101A sign prefix of
102.Sq -
103indicates a negative number
104and
105.Sq 0x
106and
107.Sq 0X
108indicate hexadecimal representation,
109otherwise decimal representation is assumed.
110After skipping the sign and base prefixes, an intermediate conversion into a
111.Vt BIGNUM
112is performed using
113.Xr BN_dec2bn 3
114or
115.Xr BN_hex2bn 3
116and the
117.Vt ASN1_INTEGER
118is then obtained with
119.Xr BN_to_ASN1_INTEGER 3 .
120.Pp
121.Fn i2s_ASN1_OCTET_STRING
122converts the octets in
123.Fa aos
124into a string where the octets are represented by pairs of colon-separated
125hexadecimal digits.
126.Pp
127.Fn s2i_ASN1_OCTET_STRING
128converts the NUL-terminated string
129.Fa str
130into an
131.Vt ASN1_OCTET_STRING .
132The
133.Fa method
134and
135.Fa ctx
136arguments are ignored.
137Every pair of hexadecimal digits is converted into an octet, while
138any number of colons separating two pairs are ignored.
139.Pp
140.Fn i2s_ASN1_ENUMERATED_TABLE
141uses strings provided in the usr_data field of the non-NULL
142.Fa method
143to convert the value of
144.Fa a
145into a string.
146If no such string is available,
147.Fa a
148is passed to
149.Fn i2s_ASN1_ENUMERATED .
150The
151.Fa method
152argument can be provided by application programs or it can be a
153default method obtained from
154.Xr X509V3_METHOD_get_nid 3 .
155The default
156.Fa methods
157corresponding to the following
158.Fa nid
159arguments have strings configured in their usr_data field:
160.Pp
161.Bl -column NID_netscape_cert_type "Netscape certificate type (obsolete)" -compact
162.It Dv NID_crl_reason Ta reason codes, RFC 5280, 5.3.1
163.It Dv NID_key_usage Ta key usage, RFC 5280, 4.2.1.3
164.It Dv NID_netscape_cert_type Ta Netscape certificate type (obsolete)
165.El
166.Sh RETURN VALUES
167.Fn i2s_ASN1_ENUMERATED ,
168.Fn i2s_ASN1_ENUMERATED_TABLE ,
169.Fn i2s_ASN1_INTEGER ,
170and
171.Fn i2s_ASN1_OCTET_STRING
172return a NUL-terminated string, or NULL on error,
173usually memory allocation failure.
174.Pp
175.Fn s2i_ASN1_INTEGER
176returns an
177.Vt ASN1_INTEGER ,
178or NULL on error.
179.Pp
180.Fn s2i_ASN1_OCTET_STRING
181returns an
182.Vt ASN1_OCTET_STRING ,
183or NULL on error.
184.Pp
185Error codes can be obtained by
186.Xr ERR_get_error 3 .
187.Sh SEE ALSO
188.Xr ASN1_INTEGER_new 3 ,
189.Xr ASN1_INTEGER_to_BN 3 ,
190.Xr ASN1_OCTET_STRING_new 3 ,
191.Xr X509V3_get_d2i 3
192.Sh HISTORY
193These functions first appeared in OpenSSL 0.9.4 and
194have been available since
195.Ox 2.6 .