Home | History | Annotate | Line # | Download | only in man3
      1 =pod
      2 
      3 =head1 NAME
      4 
      5 BIO_f_base64 - base64 BIO filter
      6 
      7 =head1 SYNOPSIS
      8 
      9 =for openssl multiple includes
     10 
     11  #include <openssl/bio.h>
     12  #include <openssl/evp.h>
     13 
     14  const BIO_METHOD *BIO_f_base64(void);
     15 
     16 =head1 DESCRIPTION
     17 
     18 BIO_f_base64() returns the base64 BIO method. This is a filter
     19 BIO that base64 encodes any data written through it and decodes
     20 any data read through it.
     21 
     22 Base64 BIOs do not support BIO_gets() or BIO_puts().
     23 
     24 For writing, by default output is divided to lines of length 64
     25 characters and there is a newline at the end of output.
     26 This behavior can be changed with B<BIO_FLAGS_BASE64_NO_NL> flag.
     27 
     28 For reading, first line should be at most 1024 bytes long including newline
     29 unless the flag B<BIO_FLAGS_BASE64_NO_NL> is set.
     30 Further input lines can be of any length (i.e., newlines may appear anywhere
     31 in the input) and a newline at the end of input is not needed.
     32 
     33 BIO_flush() on a base64 BIO that is being written through is
     34 used to signal that no more data is to be encoded: this is used
     35 to flush the final block through the BIO.
     36 
     37 The flag B<BIO_FLAGS_BASE64_NO_NL> can be set with BIO_set_flags().
     38 For writing, it causes all data to be written on one line without
     39 newline at the end.
     40 For reading, it removes all expectations on newlines in the input data.
     41 
     42 =head1 NOTES
     43 
     44 Because of the format of base64 encoding the end of the encoded
     45 block cannot always be reliably determined.
     46 
     47 =head1 RETURN VALUES
     48 
     49 BIO_f_base64() returns the base64 BIO method.
     50 
     51 =head1 EXAMPLES
     52 
     53 Base64 encode the string "Hello World\n" and write the result
     54 to standard output:
     55 
     56  BIO *bio, *b64;
     57  char message[] = "Hello World \n";
     58 
     59  b64 = BIO_new(BIO_f_base64());
     60  bio = BIO_new_fp(stdout, BIO_NOCLOSE);
     61  BIO_push(b64, bio);
     62  BIO_write(b64, message, strlen(message));
     63  BIO_flush(b64);
     64 
     65  BIO_free_all(b64);
     66 
     67 Read Base64 encoded data from standard input and write the decoded
     68 data to standard output:
     69 
     70  BIO *bio, *b64, *bio_out;
     71  char inbuf[512];
     72  int inlen;
     73 
     74  b64 = BIO_new(BIO_f_base64());
     75  bio = BIO_new_fp(stdin, BIO_NOCLOSE);
     76  bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
     77  BIO_push(b64, bio);
     78  while ((inlen = BIO_read(b64, inbuf, 512)) > 0)
     79      BIO_write(bio_out, inbuf, inlen);
     80 
     81  BIO_flush(bio_out);
     82  BIO_free_all(b64);
     83 
     84 =head1 BUGS
     85 
     86 On decoding, if the flag B<BIO_FLAGS_BASE64_NO_NL> is not set and
     87 the first 1024 bytes of input do not include a newline character
     88 the first two lines of input are ignored.
     89 
     90 The ambiguity of EOF in base64 encoded data can cause additional
     91 data following the base64 encoded block to be misinterpreted.
     92 
     93 There should be some way of specifying a test that the BIO can perform
     94 to reliably determine EOF (for example a MIME boundary).
     95 
     96 =head1 COPYRIGHT
     97 
     98 Copyright 2000-2024 The OpenSSL Project Authors. All Rights Reserved.
     99 
    100 Licensed under the Apache License 2.0 (the "License").  You may not use
    101 this file except in compliance with the License.  You can obtain a copy
    102 in the file LICENSE in the source distribution or at
    103 L<https://www.openssl.org/source/license.html>.
    104 
    105 =cut
    106