xref: /freebsd/crypto/openssl/doc/man3/BIO_push.pod (revision 02e9120893770924227138ba49df1edb3896112a)
1=pod
2
3=head1 NAME
4
5BIO_push, BIO_pop, BIO_set_next - add and remove BIOs from a chain
6
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10
11 BIO *BIO_push(BIO *b, BIO *next);
12 BIO *BIO_pop(BIO *b);
13 void BIO_set_next(BIO *b, BIO *next);
14
15=head1 DESCRIPTION
16
17BIO_push() pushes I<b> on I<next>.
18If I<b> is NULL the function does nothing and returns I<next>.
19Otherwise it prepends I<b>, which may be a single BIO or a chain of BIOs,
20to I<next> (unless I<next> is NULL).
21It then makes a control call on I<b> and returns I<b>.
22
23BIO_pop() removes the BIO I<b> from any chain is is part of.
24If I<b> is NULL the function does nothing and returns NULL.
25Otherwise it makes a control call on I<b> and
26returns the next BIO in the chain, or NULL if there is no next BIO.
27The removed BIO becomes a single BIO with no association with
28the original chain, it can thus be freed or be made part of a different chain.
29
30BIO_set_next() replaces the existing next BIO in a chain with the BIO pointed to
31by I<next>. The new chain may include some of the same BIOs from the old chain
32or it may be completely different.
33
34=head1 NOTES
35
36The names of these functions are perhaps a little misleading. BIO_push()
37joins two BIO chains whereas BIO_pop() deletes a single BIO from a chain,
38the deleted BIO does not need to be at the end of a chain.
39
40The process of calling BIO_push() and BIO_pop() on a BIO may have additional
41consequences (a control call is made to the affected BIOs).
42Any effects will be noted in the descriptions of individual BIOs.
43
44=head1 RETURN VALUES
45
46BIO_push() returns the head of the chain,
47which usually is I<b>, or I<next> if I<b> is NULL.
48
49BIO_pop() returns the next BIO in the chain,
50or NULL if there is no next BIO.
51
52=head1 EXAMPLES
53
54For these examples suppose I<md1> and I<md2> are digest BIOs,
55I<b64> is a base64 BIO and I<f> is a file BIO.
56
57If the call:
58
59 BIO_push(b64, f);
60
61is made then the new chain will be I<b64-f>. After making the calls
62
63 BIO_push(md2, b64);
64 BIO_push(md1, md2);
65
66the new chain is I<md1-md2-b64-f>. Data written to I<md1> will be digested
67by I<md1> and I<md2>, base64 encoded, and finally written to I<f>.
68
69It should be noted that reading causes data to pass in the reverse
70direction, that is data is read from I<f>, base64 decoded,
71and digested by I<md2> and then I<md1>.
72
73The call:
74
75 BIO_pop(md2);
76
77will return I<b64> and the new chain will be I<md1-b64-f>.
78Data can be written to and read from I<md1> as before,
79except that I<md2> will no more be applied.
80
81=head1 SEE ALSO
82
83L<bio(7)>
84
85=head1 HISTORY
86
87The BIO_set_next() function was added in OpenSSL 1.1.0.
88
89=head1 COPYRIGHT
90
91Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
92
93Licensed under the Apache License 2.0 (the "License").  You may not use
94this file except in compliance with the License.  You can obtain a copy
95in the file LICENSE in the source distribution or at
96L<https://www.openssl.org/source/license.html>.
97
98=cut
99