BIO_f_base64.pod 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. =pod
  2. =head1 NAME
  3. BIO_f_base64 - base64 BIO filter
  4. =head1 SYNOPSIS
  5. =for comment 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, output is by default divided to lines of length 64
  15. characters and there is always a newline at the end of output.
  16. For reading, first line should be at most 1024
  17. characters long. If it is longer then it is ignored completely.
  18. Other input lines can be of any length. There must be a newline
  19. at the end of input.
  20. This behavior can be changed with BIO_FLAGS_BASE64_NO_NL flag.
  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 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 forces the decoder to process the data regardless
  28. of newlines. All newlines are ignored and the input does not need
  29. to contain any newline at all.
  30. =head1 NOTES
  31. Because of the format of base64 encoding the end of the encoded
  32. block cannot always be reliably determined.
  33. =head1 RETURN VALUES
  34. BIO_f_base64() returns the base64 BIO method.
  35. =head1 EXAMPLES
  36. Base64 encode the string "Hello World\n" and write the result
  37. to standard output:
  38. BIO *bio, *b64;
  39. char message[] = "Hello World \n";
  40. b64 = BIO_new(BIO_f_base64());
  41. bio = BIO_new_fp(stdout, BIO_NOCLOSE);
  42. BIO_push(b64, bio);
  43. BIO_write(b64, message, strlen(message));
  44. BIO_flush(b64);
  45. BIO_free_all(b64);
  46. Read Base64 encoded data from standard input and write the decoded
  47. data to standard output:
  48. BIO *bio, *b64, *bio_out;
  49. char inbuf[512];
  50. int inlen;
  51. b64 = BIO_new(BIO_f_base64());
  52. bio = BIO_new_fp(stdin, BIO_NOCLOSE);
  53. bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
  54. BIO_push(b64, bio);
  55. while ((inlen = BIO_read(b64, inbuf, 512)) > 0)
  56. BIO_write(bio_out, inbuf, inlen);
  57. BIO_flush(bio_out);
  58. BIO_free_all(b64);
  59. =head1 BUGS
  60. The ambiguity of EOF in base64 encoded data can cause additional
  61. data following the base64 encoded block to be misinterpreted.
  62. There should be some way of specifying a test that the BIO can perform
  63. to reliably determine EOF (for example a MIME boundary).
  64. =head1 COPYRIGHT
  65. Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
  66. Licensed under the OpenSSL license (the "License"). You may not use
  67. this file except in compliance with the License. You can obtain a copy
  68. in the file LICENSE in the source distribution or at
  69. L<https://www.openssl.org/source/license.html>.
  70. =cut