blob: 6c78f7e5466f53eab7ec19393bf65ec8e7960a1b [file] [log] [blame]
Dr. Stephen Hensonb1ccd572000-09-11 01:04:09 +00001=pod
2
3=head1 NAME
4
Richard Levitte8eec1382000-09-14 20:24:56 +00005BIO_f_base64 - base64 BIO filter
Dr. Stephen Hensonb1ccd572000-09-11 01:04:09 +00006
7=head1 SYNOPSIS
8
9 #include <openssl/bio.h>
10 #include <openssl/evp.h>
11
Rich Salz1bc74512016-05-20 08:11:46 -040012 const BIO_METHOD * BIO_f_base64(void);
Dr. Stephen Hensonb1ccd572000-09-11 01:04:09 +000013
14=head1 DESCRIPTION
15
16BIO_f_base64() returns the base64 BIO method. This is a filter
17BIO that base64 encodes any data written through it and decodes
18any data read through it.
19
Rich Salz1bc74512016-05-20 08:11:46 -040020Base64 BIOs do not support BIO_gets() or BIO_puts().
Dr. Stephen Hensonb1ccd572000-09-11 01:04:09 +000021
22BIO_flush() on a base64 BIO that is being written through is
23used to signal that no more data is to be encoded: this is used
24to flush the final block through the BIO.
25
26The flag BIO_FLAGS_BASE64_NO_NL can be set with BIO_set_flags()
27to encode the data all on one line or expect the data to be all
28on one line.
29
30=head1 NOTES
31
32Because of the format of base64 encoding the end of the encoded
33block cannot always be reliably determined.
34
35=head1 RETURN VALUES
36
37BIO_f_base64() returns the base64 BIO method.
38
39=head1 EXAMPLES
40
41Base64 encode the string "Hello World\n" and write the result
42to standard output:
43
44 BIO *bio, *b64;
45 char message[] = "Hello World \n";
46
47 b64 = BIO_new(BIO_f_base64());
48 bio = BIO_new_fp(stdout, BIO_NOCLOSE);
Rich Salzfc1d88f2014-07-02 22:42:40 -040049 BIO_push(b64, bio);
50 BIO_write(b64, message, strlen(message));
51 BIO_flush(b64);
Dr. Stephen Hensonb1ccd572000-09-11 01:04:09 +000052
Rich Salzfc1d88f2014-07-02 22:42:40 -040053 BIO_free_all(b64);
Dr. Stephen Hensonb1ccd572000-09-11 01:04:09 +000054
55Read Base64 encoded data from standard input and write the decoded
56data to standard output:
57
Dr. Stephen Hensonc2dac352003-05-18 23:10:46 +000058 BIO *bio, *b64, *bio_out;
Dr. Stephen Hensonb1ccd572000-09-11 01:04:09 +000059 char inbuf[512];
60 int inlen;
Dr. Stephen Hensonb1ccd572000-09-11 01:04:09 +000061
62 b64 = BIO_new(BIO_f_base64());
63 bio = BIO_new_fp(stdin, BIO_NOCLOSE);
64 bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
Rich Salzfc1d88f2014-07-02 22:42:40 -040065 BIO_push(b64, bio);
Rich Salz1bc74512016-05-20 08:11:46 -040066 while((inlen = BIO_read(b64, inbuf, 512)) > 0)
67 BIO_write(bio_out, inbuf, inlen);
Dr. Stephen Hensonb1ccd572000-09-11 01:04:09 +000068
Rich Salzfc1d88f2014-07-02 22:42:40 -040069 BIO_flush(bio_out);
70 BIO_free_all(b64);
Dr. Stephen Hensonb1ccd572000-09-11 01:04:09 +000071
72=head1 BUGS
73
74The ambiguity of EOF in base64 encoded data can cause additional
75data following the base64 encoded block to be misinterpreted.
76
77There should be some way of specifying a test that the BIO can perform
78to reliably determine EOF (for example a MIME boundary).
79
Rich Salze2f92612016-05-18 11:44:05 -040080=head1 COPYRIGHT
81
82Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
83
84Licensed under the OpenSSL license (the "License"). You may not use
85this file except in compliance with the License. You can obtain a copy
86in the file LICENSE in the source distribution or at
87L<https://www.openssl.org/source/license.html>.
88
89=cut