base64.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * \file base64.h
  3. *
  4. * \brief RFC 1521 base64 encoding/decoding
  5. *
  6. * Copyright (C) 2006-2010, Brainspark B.V.
  7. *
  8. * This file is part of PolarSSL (http://www.polarssl.org)
  9. * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
  10. *
  11. * All rights reserved.
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License along
  24. * with this program; if not, write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  26. */
  27. #ifndef POLARSSL_BASE64_H
  28. #define POLARSSL_BASE64_H
  29. #include <string.h>
  30. #define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL -0x0010 /**< Output buffer too small. */
  31. #define POLARSSL_ERR_BASE64_INVALID_CHARACTER -0x0012 /**< Invalid character in input. */
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /**
  36. * \brief Encode a buffer into base64 format
  37. *
  38. * \param dst destination buffer
  39. * \param dlen size of the buffer
  40. * \param src source buffer
  41. * \param slen amount of data to be encoded
  42. *
  43. * \return 0 if successful, or POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL.
  44. * *dlen is always updated to reflect the amount
  45. * of data that has (or would have) been written.
  46. *
  47. * \note Call this function with *dlen = 0 to obtain the
  48. * required buffer size in *dlen
  49. */
  50. int base64_encode( unsigned char *dst, size_t *dlen,
  51. const unsigned char *src, size_t slen );
  52. /**
  53. * \brief Decode a base64-formatted buffer
  54. *
  55. * \param dst destination buffer
  56. * \param dlen size of the buffer
  57. * \param src source buffer
  58. * \param slen amount of data to be decoded
  59. *
  60. * \return 0 if successful, POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL, or
  61. * POLARSSL_ERR_BASE64_INVALID_DATA if the input data is not
  62. * correct. *dlen is always updated to reflect the amount
  63. * of data that has (or would have) been written.
  64. *
  65. * \note Call this function with *dlen = 0 to obtain the
  66. * required buffer size in *dlen
  67. */
  68. int base64_decode( unsigned char *dst, size_t *dlen,
  69. const unsigned char *src, size_t slen );
  70. /**
  71. * \brief Checkup routine
  72. *
  73. * \return 0 if successful, or 1 if the test failed
  74. */
  75. int base64_self_test( int verbose );
  76. #ifdef __cplusplus
  77. }
  78. #endif
  79. #endif /* base64.h */