xref: /openbsd-src/lib/libcrypto/man/BIO_f_base64.3 (revision fc405d53b73a2d73393cb97f684863d17b583e38)
1.\"	$OpenBSD: BIO_f_base64.3,v 1.13 2023/04/11 16:58:43 schwarze Exp $
2.\"	OpenSSL fc1d88f0 Wed Jul 2 22:42:40 2014 -0400
3.\"
4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5.\" Copyright (c) 2000, 2003, 2005, 2014 The OpenSSL Project.
6.\" All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in
17.\"    the documentation and/or other materials provided with the
18.\"    distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\"    software must display the following acknowledgment:
22.\"    "This product includes software developed by the OpenSSL Project
23.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\"    endorse or promote products derived from this software without
27.\"    prior written permission. For written permission, please contact
28.\"    openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\"    nor may "OpenSSL" appear in their names without prior written
32.\"    permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\"    acknowledgment:
36.\"    "This product includes software developed by the OpenSSL Project
37.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: April 11 2023 $
53.Dt BIO_F_BASE64 3
54.Os
55.Sh NAME
56.Nm BIO_f_base64
57.Nd base64 BIO filter
58.Sh SYNOPSIS
59.In openssl/bio.h
60.In openssl/evp.h
61.Ft const BIO_METHOD *
62.Fo BIO_f_base64
63.Fa void
64.Fc
65.Sh DESCRIPTION
66.Fn BIO_f_base64
67returns the base64 BIO method.
68This is a filter BIO that base64 encodes any data written through it
69and decodes any data read through it.
70.Pp
71Base64 BIOs do not support
72.Xr BIO_gets 3
73or
74.Xr BIO_puts 3 .
75.Pp
76.Xr BIO_flush 3
77on a base64 BIO that is being written through
78is used to signal that no more data is to be encoded:
79this is used to flush the final block through the BIO.
80.Pp
81To encode the data all on one line and to expect the data to be all
82on one line, initialize the base64 BIO as follows:
83.Bd -literal -offset indent
84BIO *b64 = BIO_new(BIO_f_base64());
85BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
86.Ed
87.Sh RETURN VALUES
88.Fn BIO_f_base64
89returns the base64 BIO method.
90.Pp
91When called on a base64 BIO object,
92.Xr BIO_method_type 3
93returns the constant
94.Dv BIO_TYPE_BASE64
95and
96.Xr BIO_method_name 3
97returns a pointer to the static string
98.Qq base64 encoding .
99.Sh EXAMPLES
100Base64 encode the string "hello, world\en"
101and write the result to standard output:
102.Bd -literal -offset indent
103BIO *bio, *b64;
104char message[] = "hello, world\en";
105
106b64 = BIO_new(BIO_f_base64());
107bio = BIO_new_fp(stdout, BIO_NOCLOSE);
108BIO_push(b64, bio);
109BIO_write(b64, message, strlen(message));
110BIO_flush(b64);
111
112BIO_free_all(b64);
113.Ed
114.Pp
115Read Base64-encoded data from standard input
116and write the decoded data to standard output:
117.Bd -literal -offset indent
118BIO *bio, *b64, *bio_out;
119char inbuf[512];
120int inlen;
121
122b64 = BIO_new(BIO_f_base64());
123bio = BIO_new_fp(stdin, BIO_NOCLOSE);
124bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
125BIO_push(b64, bio);
126while((inlen = BIO_read(b64, inbuf, 512)) > 0)
127	BIO_write(bio_out, inbuf, inlen);
128
129BIO_flush(bio_out);
130BIO_free_all(b64);
131.Ed
132.Sh SEE ALSO
133.Xr BIO_new 3 ,
134.Xr EVP_EncodeInit 3
135.Sh HISTORY
136.Fn BIO_f_base64
137first appeared in SSLeay 0.6.5 and has been available since
138.Ox 2.4 .
139.Sh BUGS
140The ambiguity of EOF in base64-encoded data can cause additional
141data following the base64-encoded block to be misinterpreted.
142.Pp
143There should be some way of specifying a test that the BIO can perform
144to reliably determine EOF (for example a MIME boundary).
145