summaryrefslogtreecommitdiff
path: root/lib/libcrypto/man/d2i_ASN1_BOOLEAN.3
blob: 3f83f3e85807250ceda71338faf7d6fb3fccfc04 (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
.\" $OpenBSD: d2i_ASN1_BOOLEAN.3,v 1.3 2021/12/09 19:03:14 schwarze Exp $
.\"
.\" Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: December 9 2021 $
.Dt D2I_ASN1_BOOLEAN 3
.Os
.Sh NAME
.Nm d2i_ASN1_BOOLEAN ,
.Nm i2d_ASN1_BOOLEAN
.Nd decode and encode an ASN.1 BOOLEAN value
.Sh SYNOPSIS
.In openssl/asn1.h
.Bd -unfilled
typedef int ASN1_BOOLEAN;
.Ed
.Pp
.Ft int
.Fo d2i_ASN1_BOOLEAN
.Fa "int *val_out"
.Fa "const unsigned char **der_in"
.Fa "long length"
.Fc
.Ft int
.Fo i2d_ASN1_BOOLEAN
.Fa "int val_in"
.Fa "unsigned char **der_out"
.Fc
.Sh DESCRIPTION
These functions decode and encode
an ASN.1 value TRUE or FALSE of the type BOOLEAN.
In contrast to most other ASN.1 types,
the library does not represent the BOOLEAN type by a structure.
Instead,
.Vt ASN1_BOOLEAN
is simply an alias for the type
.Vt int .
This type is also represented by the type identifier constant
.Dv V_ASN1_BOOLEAN .
.Pp
.Fn d2i_ASN1_BOOLEAN
verifies that the BER-encoded value at
.Pf * Fa der_in
is of the type BOOLEAN
and that the number encoded in the length octets is 1.
At most
.Fa length
bytes are inspected.
.Pp
Unless
.Fa val_out
is a
.Dv NULL
pointer, it copies the integer value of the single content octet to
.Pf * Fa val_out .
In case of success,
.Pf * Fa der_in
is advanced by three bytes to the byte after the content octet.
.Pp
.Fn i2d_ASN1_BOOLEAN
encodes an ASN.1 value of the type BOOLEAN using DER.
Specifically, unless
.Fa der_out
is a
.Dv NULL
pointer, it writes the identifier octet for the type BOOLEAN,
0x01, the single length octet 0x01, one single content octet containing
.Fa val_in ,
and no end-of-content octets to
.Pf * Fa der_out
and advances the pointer
.Pf * Fa der_out
by three bytes to the byte after the content octet.
Making sure that three bytes can be written to
.Pf * Fa der_out
is the responsibility of the caller.
.Pp
If
.Fa val_in
is 0, it encodes the FALSE value.
If
.Fa val_in
is in the range from 1 to 255 inclusive, it encodes the TRUE value.
.Sh RETURN VALUES
In case of success,
.Fn d2i_ASN1_BOOLEAN
returns the integer value of the content octet.
The number 0 represents the FALSE value and any number in the range
from 1 to 255 inclusive represents the TRUE value.
If the
.Fa length
argument is less than 3, if parsing fails, if the ASN.1 object at
.Pf * Fa der_in
is not of the type BOOLEAN, or if the number of content octets is not 1,
.Fn d2i_ASN1_BOOLEAN
returns \-1 to indicate the error.
.Pp
.Fn i2d_ASN1_BOOLEAN
always returns 3, which is the number of bytes in the BER encoding
of an ASN.1 BOOLEAN value.
.Sh SEE ALSO
.Xr ASN1_get_object 3 ,
.Xr ASN1_item_d2i 3 ,
.Xr ASN1_put_object 3
.Sh STANDARDS
ITU-T Recommendation X.690, also known as ISO/IEC 8825-1:
Information technology - ASN.1 encoding rules:
Specification of Basic Encoding Rules (BER), Canonical Encoding
Rules (CER) and Distinguished Encoding Rules (DER),
section 8.2: Encoding of a boolean value
.Sh HISTORY
.Fn d2i_ASN1_BOOLEAN
and
.Fn i2d_ASN1_BOOLEAN
first appeared in SSLeay 0.6.2 and have been available since
.Ox 2.4 .
.Sh CAVEATS
The behaviour of
.Fn i2d_ASN1_BOOLEAN
is unspecified if
.Fa val_in
is negative or larger than 255.