BIO_f_base64.pod 2.9 KB

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