1.\" $OpenBSD: ASN1_BIT_STRING_set.3,v 1.4 2023/07/28 05:53:10 tb Exp $
2.\"
3.\" Copyright (c) 2021 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: July 28 2023 $
18.Dt ASN1_BIT_STRING_SET 3
19.Os
20.Sh NAME
21.Nm ASN1_BIT_STRING_set ,
22.Nm ASN1_BIT_STRING_set_bit ,
23.Nm ASN1_BIT_STRING_get_bit
24.Nd ASN.1 BIT STRING accessors
25.Sh SYNOPSIS
26.In openssl/asn1.h
27.Ft int
28.Fo ASN1_BIT_STRING_set
29.Fa "ASN1_BIT_STRING *bitstr"
30.Fa "unsigned char *data"
31.Fa "int len"
32.Fc
33.Ft int
34.Fo ASN1_BIT_STRING_set_bit
35.Fa "ASN1_BIT_STRING *bitstr"
36.Fa "int bitnumber"
37.Fa "int set"
38.Fc
39.Ft int
40.Fo ASN1_BIT_STRING_get_bit
41.Fa "ASN1_BIT_STRING *bitstr"
42.Fa "int bitnumber"
43.Fc
44.Sh DESCRIPTION
45.Fn ASN1_BIT_STRING_set
46sets the length attribute of
47.Fa bitstr
48to
49.Fa len
50and copies that number of bytes from
51.Fa data
52into
53.Fa bitstr ,
54overwriting any previous data, by merely calling
55.Xr ASN1_STRING_set 3 .
56This function does no validation whatsoever.
57In particular, it neither checks that
58.Fa bitstr
59is actually of the type
60.Dv V_ASN1_BIT_STRING
61nor, even if it is, that the
62.Fa data
63and
64.Fa len
65arguments make sense for this particular bit string.
66.Pp
67If the
68.Fa set
69argument is non-zero,
70.Fn ASN1_BIT_STRING_set_bit
71sets the bit with the given
72.Fa bitnumber
73in the
74.Fa bitstr ;
75otherwise, it clears that bit.
76A
77.Fa bitnumber
78of 0 addresses the most significant bit in the first data byte of
79.Fa bitstr ,
807 the least significant bit in the same byte,
818 the most significant bit in the second data byte, and so on.
82.Pp
83If setting a bit is requested beyond the last existing data byte,
84additional bytes are added to the
85.Fa bitstr
86as needed.
87After clearing a bit, any trailing NUL bytes are removed from the
88.Fa bitstr .
89.Pp
90.Fn ASN1_BIT_STRING_get_bit
91checks that the bit with the given
92.Fa bitnumber
93is set in
94.Fa bitstr .
95.Sh RETURN VALUES
96.Fn ASN1_BIT_STRING_set
97returns 1 on success or 0 if memory allocation fails or if
98.Fa data
99is
100.Dv NULL
101and
102.Fa len
103is \-1 in the same call.
104.Pp
105.Fn ASN1_BIT_STRING_set_bit
106returns 1 on success or 0 if
107.Fa bitstr
108is
109.Dv NULL
110or if memory allocation fails.
111.Pp
112.Fn ASN1_BIT_STRING_get_bit
113returns 1 if the bit with the given
114.Fa bitnumber
115is set in the
116.Fa bitstr
117or 0 if
118.Fa bitstr
119is
120.Dv NULL ,
121if
122.Fa bitnumber
123points beyond the last data byte in
124.Fa bitstr ,
125or if the requested bit is not set.
126.Sh SEE ALSO
127.Xr ASN1_BIT_STRING_new 3 ,
128.Xr ASN1_STRING_set 3 ,
129.Xr d2i_ASN1_BIT_STRING 3
130.Sh HISTORY
131.Fn ASN1_BIT_STRING_set
132first appeared in SSLeay 0.6.5.
133.Fn ASN1_BIT_STRING_set_bit
134and
135.Fn ASN1_BIT_STRING_get_bit
136first appeared in SSLeay 0.9.0.
137These functions have been available since
138.Ox 2.4 .
139