1*e71b7053SJung-uk Kim=pod 2*e71b7053SJung-uk Kim 3*e71b7053SJung-uk Kim=head1 NAME 4*e71b7053SJung-uk Kim 5*e71b7053SJung-uk KimBIO_f_base64 - base64 BIO filter 6*e71b7053SJung-uk Kim 7*e71b7053SJung-uk Kim=head1 SYNOPSIS 8*e71b7053SJung-uk Kim 9*e71b7053SJung-uk Kim=for comment multiple includes 10*e71b7053SJung-uk Kim 11*e71b7053SJung-uk Kim #include <openssl/bio.h> 12*e71b7053SJung-uk Kim #include <openssl/evp.h> 13*e71b7053SJung-uk Kim 14*e71b7053SJung-uk Kim const BIO_METHOD *BIO_f_base64(void); 15*e71b7053SJung-uk Kim 16*e71b7053SJung-uk Kim=head1 DESCRIPTION 17*e71b7053SJung-uk Kim 18*e71b7053SJung-uk KimBIO_f_base64() returns the base64 BIO method. This is a filter 19*e71b7053SJung-uk KimBIO that base64 encodes any data written through it and decodes 20*e71b7053SJung-uk Kimany data read through it. 21*e71b7053SJung-uk Kim 22*e71b7053SJung-uk KimBase64 BIOs do not support BIO_gets() or BIO_puts(). 23*e71b7053SJung-uk Kim 24*e71b7053SJung-uk KimBIO_flush() on a base64 BIO that is being written through is 25*e71b7053SJung-uk Kimused to signal that no more data is to be encoded: this is used 26*e71b7053SJung-uk Kimto flush the final block through the BIO. 27*e71b7053SJung-uk Kim 28*e71b7053SJung-uk KimThe flag BIO_FLAGS_BASE64_NO_NL can be set with BIO_set_flags() 29*e71b7053SJung-uk Kimto encode the data all on one line or expect the data to be all 30*e71b7053SJung-uk Kimon one line. 31*e71b7053SJung-uk Kim 32*e71b7053SJung-uk Kim=head1 NOTES 33*e71b7053SJung-uk Kim 34*e71b7053SJung-uk KimBecause of the format of base64 encoding the end of the encoded 35*e71b7053SJung-uk Kimblock cannot always be reliably determined. 36*e71b7053SJung-uk Kim 37*e71b7053SJung-uk Kim=head1 RETURN VALUES 38*e71b7053SJung-uk Kim 39*e71b7053SJung-uk KimBIO_f_base64() returns the base64 BIO method. 40*e71b7053SJung-uk Kim 41*e71b7053SJung-uk Kim=head1 EXAMPLES 42*e71b7053SJung-uk Kim 43*e71b7053SJung-uk KimBase64 encode the string "Hello World\n" and write the result 44*e71b7053SJung-uk Kimto standard output: 45*e71b7053SJung-uk Kim 46*e71b7053SJung-uk Kim BIO *bio, *b64; 47*e71b7053SJung-uk Kim char message[] = "Hello World \n"; 48*e71b7053SJung-uk Kim 49*e71b7053SJung-uk Kim b64 = BIO_new(BIO_f_base64()); 50*e71b7053SJung-uk Kim bio = BIO_new_fp(stdout, BIO_NOCLOSE); 51*e71b7053SJung-uk Kim BIO_push(b64, bio); 52*e71b7053SJung-uk Kim BIO_write(b64, message, strlen(message)); 53*e71b7053SJung-uk Kim BIO_flush(b64); 54*e71b7053SJung-uk Kim 55*e71b7053SJung-uk Kim BIO_free_all(b64); 56*e71b7053SJung-uk Kim 57*e71b7053SJung-uk KimRead Base64 encoded data from standard input and write the decoded 58*e71b7053SJung-uk Kimdata to standard output: 59*e71b7053SJung-uk Kim 60*e71b7053SJung-uk Kim BIO *bio, *b64, *bio_out; 61*e71b7053SJung-uk Kim char inbuf[512]; 62*e71b7053SJung-uk Kim int inlen; 63*e71b7053SJung-uk Kim 64*e71b7053SJung-uk Kim b64 = BIO_new(BIO_f_base64()); 65*e71b7053SJung-uk Kim bio = BIO_new_fp(stdin, BIO_NOCLOSE); 66*e71b7053SJung-uk Kim bio_out = BIO_new_fp(stdout, BIO_NOCLOSE); 67*e71b7053SJung-uk Kim BIO_push(b64, bio); 68*e71b7053SJung-uk Kim while ((inlen = BIO_read(b64, inbuf, 512)) > 0) 69*e71b7053SJung-uk Kim BIO_write(bio_out, inbuf, inlen); 70*e71b7053SJung-uk Kim 71*e71b7053SJung-uk Kim BIO_flush(bio_out); 72*e71b7053SJung-uk Kim BIO_free_all(b64); 73*e71b7053SJung-uk Kim 74*e71b7053SJung-uk Kim=head1 BUGS 75*e71b7053SJung-uk Kim 76*e71b7053SJung-uk KimThe ambiguity of EOF in base64 encoded data can cause additional 77*e71b7053SJung-uk Kimdata following the base64 encoded block to be misinterpreted. 78*e71b7053SJung-uk Kim 79*e71b7053SJung-uk KimThere should be some way of specifying a test that the BIO can perform 80*e71b7053SJung-uk Kimto reliably determine EOF (for example a MIME boundary). 81*e71b7053SJung-uk Kim 82*e71b7053SJung-uk Kim=head1 COPYRIGHT 83*e71b7053SJung-uk Kim 84*e71b7053SJung-uk KimCopyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. 85*e71b7053SJung-uk Kim 86*e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License"). You may not use 87*e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 88*e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 89*e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 90*e71b7053SJung-uk Kim 91*e71b7053SJung-uk Kim=cut 92