Dr. Stephen Henson | b1ccd57 | 2000-09-11 01:04:09 +0000 | [diff] [blame] | 1 | =pod |
| 2 | |
| 3 | =head1 NAME |
| 4 | |
Richard Levitte | 8eec138 | 2000-09-14 20:24:56 +0000 | [diff] [blame] | 5 | BIO_f_base64 - base64 BIO filter |
Dr. Stephen Henson | b1ccd57 | 2000-09-11 01:04:09 +0000 | [diff] [blame] | 6 | |
| 7 | =head1 SYNOPSIS |
| 8 | |
| 9 | #include <openssl/bio.h> |
| 10 | #include <openssl/evp.h> |
| 11 | |
Rich Salz | 1bc7451 | 2016-05-20 08:11:46 -0400 | [diff] [blame] | 12 | const BIO_METHOD * BIO_f_base64(void); |
Dr. Stephen Henson | b1ccd57 | 2000-09-11 01:04:09 +0000 | [diff] [blame] | 13 | |
| 14 | =head1 DESCRIPTION |
| 15 | |
| 16 | BIO_f_base64() returns the base64 BIO method. This is a filter |
| 17 | BIO that base64 encodes any data written through it and decodes |
| 18 | any data read through it. |
| 19 | |
Rich Salz | 1bc7451 | 2016-05-20 08:11:46 -0400 | [diff] [blame] | 20 | Base64 BIOs do not support BIO_gets() or BIO_puts(). |
Dr. Stephen Henson | b1ccd57 | 2000-09-11 01:04:09 +0000 | [diff] [blame] | 21 | |
| 22 | BIO_flush() on a base64 BIO that is being written through is |
| 23 | used to signal that no more data is to be encoded: this is used |
| 24 | to flush the final block through the BIO. |
| 25 | |
| 26 | The flag BIO_FLAGS_BASE64_NO_NL can be set with BIO_set_flags() |
| 27 | to encode the data all on one line or expect the data to be all |
| 28 | on one line. |
| 29 | |
| 30 | =head1 NOTES |
| 31 | |
| 32 | Because of the format of base64 encoding the end of the encoded |
| 33 | block cannot always be reliably determined. |
| 34 | |
| 35 | =head1 RETURN VALUES |
| 36 | |
| 37 | BIO_f_base64() returns the base64 BIO method. |
| 38 | |
| 39 | =head1 EXAMPLES |
| 40 | |
| 41 | Base64 encode the string "Hello World\n" and write the result |
| 42 | to 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 Salz | fc1d88f | 2014-07-02 22:42:40 -0400 | [diff] [blame] | 49 | BIO_push(b64, bio); |
| 50 | BIO_write(b64, message, strlen(message)); |
| 51 | BIO_flush(b64); |
Dr. Stephen Henson | b1ccd57 | 2000-09-11 01:04:09 +0000 | [diff] [blame] | 52 | |
Rich Salz | fc1d88f | 2014-07-02 22:42:40 -0400 | [diff] [blame] | 53 | BIO_free_all(b64); |
Dr. Stephen Henson | b1ccd57 | 2000-09-11 01:04:09 +0000 | [diff] [blame] | 54 | |
| 55 | Read Base64 encoded data from standard input and write the decoded |
| 56 | data to standard output: |
| 57 | |
Dr. Stephen Henson | c2dac35 | 2003-05-18 23:10:46 +0000 | [diff] [blame] | 58 | BIO *bio, *b64, *bio_out; |
Dr. Stephen Henson | b1ccd57 | 2000-09-11 01:04:09 +0000 | [diff] [blame] | 59 | char inbuf[512]; |
| 60 | int inlen; |
Dr. Stephen Henson | b1ccd57 | 2000-09-11 01:04:09 +0000 | [diff] [blame] | 61 | |
| 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 Salz | fc1d88f | 2014-07-02 22:42:40 -0400 | [diff] [blame] | 65 | BIO_push(b64, bio); |
Rich Salz | 1bc7451 | 2016-05-20 08:11:46 -0400 | [diff] [blame] | 66 | while((inlen = BIO_read(b64, inbuf, 512)) > 0) |
| 67 | BIO_write(bio_out, inbuf, inlen); |
Dr. Stephen Henson | b1ccd57 | 2000-09-11 01:04:09 +0000 | [diff] [blame] | 68 | |
Rich Salz | fc1d88f | 2014-07-02 22:42:40 -0400 | [diff] [blame] | 69 | BIO_flush(bio_out); |
| 70 | BIO_free_all(b64); |
Dr. Stephen Henson | b1ccd57 | 2000-09-11 01:04:09 +0000 | [diff] [blame] | 71 | |
| 72 | =head1 BUGS |
| 73 | |
| 74 | The ambiguity of EOF in base64 encoded data can cause additional |
| 75 | data following the base64 encoded block to be misinterpreted. |
| 76 | |
| 77 | There should be some way of specifying a test that the BIO can perform |
| 78 | to reliably determine EOF (for example a MIME boundary). |
| 79 | |
Rich Salz | e2f9261 | 2016-05-18 11:44:05 -0400 | [diff] [blame] | 80 | =head1 COPYRIGHT |
| 81 | |
| 82 | Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. |
| 83 | |
| 84 | Licensed under the OpenSSL license (the "License"). You may not use |
| 85 | this file except in compliance with the License. You can obtain a copy |
| 86 | in the file LICENSE in the source distribution or at |
| 87 | L<https://www.openssl.org/source/license.html>. |
| 88 | |
| 89 | =cut |