BIO_f_base64.pod 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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, 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 expects the data to be all on one line (with or
  28. without a trailing newline).
  29. =head1 NOTES
  30. Because of the format of base64 encoding the end of the encoded
  31. block cannot always be reliably determined.
  32. =head1 RETURN VALUES
  33. BIO_f_base64() returns the base64 BIO method.
  34. =head1 EXAMPLES
  35. Base64 encode the string "Hello World\n" and write the result
  36. to standard output:
  37. BIO *bio, *b64;
  38. char message[] = "Hello World \n";
  39. b64 = BIO_new(BIO_f_base64());
  40. bio = BIO_new_fp(stdout, BIO_NOCLOSE);
  41. BIO_push(b64, bio);
  42. BIO_write(b64, message, strlen(message));
  43. BIO_flush(b64);
  44. BIO_free_all(b64);
  45. Read Base64 encoded data from standard input and write the decoded
  46. data to standard output:
  47. BIO *bio, *b64, *bio_out;
  48. char inbuf[512];
  49. int inlen;
  50. b64 = BIO_new(BIO_f_base64());
  51. bio = BIO_new_fp(stdin, BIO_NOCLOSE);
  52. bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
  53. BIO_push(b64, bio);
  54. while ((inlen = BIO_read(b64, inbuf, 512)) > 0)
  55. BIO_write(bio_out, inbuf, inlen);
  56. BIO_flush(bio_out);
  57. BIO_free_all(b64);
  58. =head1 BUGS
  59. The ambiguity of EOF in base64 encoded data can cause additional
  60. data following the base64 encoded block to be misinterpreted.
  61. There should be some way of specifying a test that the BIO can perform
  62. to reliably determine EOF (for example a MIME boundary).
  63. =head1 COPYRIGHT
  64. Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
  65. Licensed under the Apache License 2.0 (the "License"). You may not use
  66. this file except in compliance with the License. You can obtain a copy
  67. in the file LICENSE in the source distribution or at
  68. L<https://www.openssl.org/source/license.html>.
  69. =cut