base64.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* base64.h -- Encode binary data using printable characters.
  2. Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
  3. Written by Simon Josefsson.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  15. #ifndef BASE64_H
  16. # define BASE64_H
  17. /* Get size_t. */
  18. # include <stddef.h>
  19. /* Get bool. */
  20. # include <stdbool.h>
  21. /* This uses that the expression (n+(k-1))/k means the smallest
  22. integer >= n/k, i.e., the ceiling of n/k. */
  23. # define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)
  24. extern bool isbase64 (char ch);
  25. extern void base64_encode (const char *restrict in, size_t inlen,
  26. char *restrict out, size_t outlen);
  27. extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out);
  28. extern bool base64_decode (const char *restrict in, size_t inlen,
  29. char *restrict out, size_t *outlen);
  30. extern bool base64_decode_alloc (const char *in, size_t inlen,
  31. char **out, size_t *outlen);
  32. #endif /* BASE64_H */