base64.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Base64.h
  2. *
  3. * Copyright (C) Bryan Drewery
  4. *
  5. * This program is private and may not be distributed, modified
  6. * or used without express permission of Bryan Drewery.
  7. *
  8. * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY.
  9. * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
  10. * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  11. * ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
  12. * DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
  13. * POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
  16. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
  18. * IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
  19. * NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
  20. * MODIFICATIONS.
  21. *
  22. */
  23. #ifndef _W_BASE64_H
  24. #define _W_BASE64_H 1
  25. #include "bdlib.h"
  26. BDLIB_NS_BEGIN
  27. class Base64 {
  28. };
  29. /**
  30. * @brief Encode a plaintext string into base64 (returns a buffer)
  31. * @param src A c-style string to encode
  32. * @param len Reference to length of string (to be updated on return)
  33. * @return An encoded NULL-terminated c-style string (must be free()d later)
  34. */
  35. char *b64enc(const unsigned char *src, size_t *len);
  36. /**
  37. * @brief Encode a plaintext string into base64 (using a given buffer)
  38. * @param data The c-style string to encode
  39. * @param len Reference to length of string (to be updated on return)
  40. * @param dest Reference to the buffer to encode into
  41. */
  42. void b64enc_buf(const unsigned char *data, size_t *len, char *dest);
  43. /**
  44. * @brief Decode a base64 encoded string into plaintext (returns a buffer)
  45. * @param src A c-style string to decode
  46. * @param len Reference to length of string (to be updated on return)
  47. * @return A decoded NULL-terminated c-style string (must be free()d later)
  48. */
  49. char *b64dec(const unsigned char *data, size_t *len);
  50. /**
  51. * @brief Decode a base64 encoded string into plaintext (using a given buffer)
  52. * @param data The c-style string to decode
  53. * @param len Reference to length of string (to be updated on return)
  54. * @param dest Reference to the buffer to decode into
  55. */
  56. void b64dec_buf(const unsigned char *data, size_t *len, char *dest);
  57. BDLIB_NS_END
  58. #endif /* !_W_BASE64_H */