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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
|
.\" $OpenBSD: BIO_meth_new.3,v 1.5 2018/07/09 09:52:18 tb Exp $
.\" full merge up to: OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400
.\" selective merge up to: OpenSSL 61f805c1 Jan 16 01:01:46 2018 +0800
.\"
.\" This file is a derived work.
.\" The changes are covered by the following Copyright and license:
.\"
.\" Copyright (c) 2018 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.
.\"
.\" The original file was written by Matt Caswell <matt@openssl.org>
.\" Copyright (c) 2016 The OpenSSL Project. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in
.\" the documentation and/or other materials provided with the
.\" distribution.
.\"
.\" 3. All advertising materials mentioning features or use of this
.\" software must display the following acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
.\"
.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
.\" endorse or promote products derived from this software without
.\" prior written permission. For written permission, please contact
.\" openssl-core@openssl.org.
.\"
.\" 5. Products derived from this software may not be called "OpenSSL"
.\" nor may "OpenSSL" appear in their names without prior written
.\" permission of the OpenSSL Project.
.\"
.\" 6. Redistributions of any form whatsoever must retain the following
.\" acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: July 9 2018 $
.Dt BIO_METH_NEW 3
.Os
.Sh NAME
.Nm BIO_get_new_index ,
.Nm BIO_meth_new ,
.Nm BIO_meth_free ,
.Nm BIO_meth_get_write ,
.Nm BIO_meth_set_write ,
.Nm BIO_meth_get_read ,
.Nm BIO_meth_set_read ,
.Nm BIO_meth_get_puts ,
.Nm BIO_meth_set_puts ,
.Nm BIO_meth_get_gets ,
.Nm BIO_meth_set_gets ,
.Nm BIO_meth_get_ctrl ,
.Nm BIO_meth_set_ctrl ,
.Nm BIO_meth_get_create ,
.Nm BIO_meth_set_create ,
.Nm BIO_meth_get_destroy ,
.Nm BIO_meth_set_destroy ,
.Nm BIO_meth_get_callback_ctrl ,
.Nm BIO_meth_set_callback_ctrl
.Nd manipulate BIO_METHOD structures
.Sh SYNOPSIS
.In openssl/bio.h
.Ft int
.Fn BIO_get_new_index void
.Ft BIO_METHOD *
.Fo BIO_meth_new
.Fa "int type"
.Fa "const char *name"
.Fc
.Ft void
.Fo BIO_meth_free
.Fa "BIO_METHOD *biom"
.Fc
.Ft int
.Fn "(*BIO_meth_get_write(const BIO_METHOD *biom))" "BIO *" "const char *" int
.Ft int
.Fo BIO_meth_set_write
.Fa "BIO_METHOD *biom"
.Fa "int (*write)(BIO *, const char *, int)"
.Fc
.Ft int
.Fn "(*BIO_meth_get_read(const BIO_METHOD *biom))" "BIO *" "char *" int
.Ft int
.Fo BIO_meth_set_read
.Fa "BIO_METHOD *biom"
.Fa "int (*read)(BIO *, char *, int)"
.Fc
.Ft int
.Fn "(*BIO_meth_get_puts(const BIO_METHOD *biom))" "BIO *" "const char *"
.Ft int
.Fo BIO_meth_set_puts
.Fa "BIO_METHOD *biom"
.Fa "int (*puts)(BIO *, const char *)"
.Fc
.Ft int
.Fn "(*BIO_meth_get_gets(const BIO_METHOD *biom))" "BIO *" "char *" int
.Ft int
.Fo BIO_meth_set_gets
.Fa "BIO_METHOD *biom"
.Fa "int (*gets)(BIO *, char *, int)"
.Fc
.Ft long
.Fn "(*BIO_meth_get_ctrl(const BIO_METHOD *biom))" "BIO *" int long "void *"
.Ft int
.Fo BIO_meth_set_ctrl
.Fa "BIO_METHOD *biom"
.Fa "long (*ctrl)(BIO *, int, long, void *)"
.Fc
.Ft int
.Fn "(*BIO_meth_get_create(const BIO_METHOD *biom))" "BIO *"
.Ft int
.Fo BIO_meth_set_create
.Fa "BIO_METHOD *biom"
.Fa "int (*create)(BIO *)"
.Fc
.Ft int
.Fn "(*BIO_meth_get_destroy(const BIO_METHOD *biom))" "BIO *"
.Ft int
.Fo BIO_meth_set_destroy
.Fa "BIO_METHOD *biom"
.Fa "int (*destroy)(BIO *)"
.Fc
.Ft long
.Fo "(*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom))"
.Fa "BIO *"
.Fa int
.Fa "BIO_info_cb *"
.Fc
.Ft int
.Fo BIO_meth_set_callback_ctrl
.Fa "BIO_METHOD *biom"
.Fa "long (*callback_ctrl)(BIO *, int, BIO_info_cb *)"
.Fc
.Sh DESCRIPTION
The
.Vt BIO_METHOD
structure stores function pointers implementing a
.Vt BIO
type.
See
.Xr BIO_new 3
for more information about
.Vt BIO
objects.
.Pp
.Fn BIO_meth_new
creates a new
.Vt BIO_METHOD
structure.
It requires a unique integer
.Fa type ;
use
.Fn BIO_get_new_index
to get the value for
.Fa type .
Currently, the user can only create up to 127 different BIO types, and
.Fa type
is limited to the range 129\(en255.
The
.Fa name
pointer is stored in the structure and will not be freed by
.Fn BIO_meth_free .
.Pp
The standard BIO types are listed in
.In openssl/bio.h .
Some examples include
.Dv BIO_TYPE_BUFFER
and
.Dv BIO_TYPE_CIPHER .
The
.Fa type
of filter BIOs should have the
.Dv BIO_TYPE_FILTER
bit set.
Source/sink BIOs should have the
.Dv BIO_TYPE_SOURCE_SINK
bit set.
File descriptor based BIOs (e.g. socket, fd, connect, accept etc.\&)
should additionally have the
.Dv BIO_TYPE_DESCRIPTOR
bit set.
See
.Xr BIO_find_type 3
for more information.
.Pp
.Fn BIO_meth_free
is an alias for
.Xr free 3 .
.Pp
.Fn BIO_meth_get_write ,
.Fn BIO_meth_set_write ,
.Fn BIO_meth_get_read ,
and
.Fn BIO_meth_set_read
get and set the functions
.Fa write
and
.Fa read
used for writing and reading arbitrary length data to and from the
.Vt BIO .
These functions are called from
.Xr BIO_write 3
and
.Xr BIO_read 3 ,
respectively.
The parameters and return values of
.Fa write
and
.Fa read
have the same meaning as for
.Xr BIO_write 3
and
.Xr BIO_read 3 .
.Pp
.Fn BIO_meth_get_puts
and
.Fn BIO_meth_set_puts
get and set the function
.Fa puts
used for writing a NUL-terminated string to the
.Vt BIO .
This function is called from
.Xr BIO_puts 3 .
The parameters and the return value of
.Fa puts
have the same meaning as for
.Xr BIO_puts 3 .
.Pp
.Fn BIO_meth_get_gets
and
.Fn BIO_meth_set_gets
get and set the function
.Fa gets
used for reading a line of data from the
.Vt BIO .
This function is called from
.Xr BIO_gets 3 .
The parameters and the return value of
.Fa gets
have the same meaning as for
.Xr BIO_gets 3 .
.Pp
.Fn BIO_meth_get_ctrl
and
.Fn BIO_meth_set_ctrl
get and set the function
.Fa ctrl
used for processing control messages in the
.Vt BIO .
This function is called from
.Xr BIO_ctrl 3 .
The parameters and return value of
.Fa ctrl
have the same meaning as for
.Xr BIO_ctrl 3 .
.Pp
.Fn BIO_meth_get_create
and
.Fn BIO_meth_set_create
get and set a function
.Fa create
used while initializing a new instance of the
.Vt BIO .
This function is called from
.Xr BIO_new 3 .
The
.Xr BIO_new 3
function allocates the memory for the new
.Vt BIO ,
and a pointer to this newly allocated structure is passed
as the parameter to
.Fa create .
.Pp
.Fn BIO_meth_get_destroy
and
.Fn BIO_meth_set_destroy
get and set a function
.Fa destroy
used while destroying an instance of a
.Vt BIO .
This function is called from
.Xr BIO_free 3 .
A pointer to the
.Vt BIO
to be destroyed is passed as the parameter.
The
.Fa destroy
function is intended to perform clean-up specific to the
.Vt BIO
.Fa type .
The memory for the
.Vt BIO
itself must not be freed by this function.
.Pp
.Fn BIO_meth_get_callback_ctrl
and
.Fn BIO_meth_set_callback_ctrl
get and set the function
.Fa callback_ctrl
used for processing callback control messages in the
.Vt BIO .
This function is called from
.Xr BIO_callback_ctrl 3 .
The parameters and return value of
.Fa callback_ctrl
have the same meaning as for
.Xr BIO_callback_ctrl 3 .
.Sh RETURN VALUES
.Fn BIO_get_new_index
returns the new BIO type value or \-1 if an error occurs.
.Pp
.Fn BIO_meth_new
returns the new
.Vt BIO_METHOD
structure or
.Dv NULL
if an error occurs.
.Pp
The
.Fn BIO_meth_set_*
functions return 1 on success or 0 on error.
Currently, they cannot fail.
.Pp
The
.Fn BIO_meth_get_*
functions return function pointers.
.Sh SEE ALSO
.Xr BIO_ctrl 3 ,
.Xr BIO_find_type 3 ,
.Xr BIO_new 3 ,
.Xr BIO_read 3
.Sh HISTORY
These functions first appeared in OpenSSL 1.1.0
and have been available since
.Ox 6.3 .
|