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