base64.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * \file base64.h
  3. */
  4. #ifndef XYSSL_BASE64_H
  5. #define XYSSL_BASE64_H
  6. #define XYSSL_ERR_BASE64_INVALID_CHARACTER -0x0012
  7. #define XYSSL_ERR_BASE64_BUFFER_TOO_SMALL -0x0010
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /**
  12. * \brief Encode a buffer into base64 format
  13. *
  14. * \param dst destination buffer
  15. * \param dlen size of the buffer
  16. * \param src source buffer
  17. * \param slen amount of data to be encoded
  18. *
  19. * \return 0 if successful, or XYSSL_ERR_BASE64_BUFFER_TOO_SMALL.
  20. * *dlen is always updated to reflect the amount
  21. * of data that has (or would have) been written.
  22. *
  23. * \note Call this function with *dlen = 0 to obtain the
  24. * required buffer size in *dlen
  25. */
  26. int base64_encode( unsigned char *dst, int *dlen,
  27. unsigned char *src, int slen );
  28. /**
  29. * \brief Decode a base64-formatted buffer
  30. *
  31. * \param dst destination buffer
  32. * \param dlen size of the buffer
  33. * \param src source buffer
  34. * \param slen amount of data to be decoded
  35. *
  36. * \return 0 if successful, XYSSL_ERR_BASE64_BUFFER_TOO_SMALL, or
  37. * XYSSL_ERR_BASE64_INVALID_DATA if the input data is not
  38. * correct. *dlen is always updated to reflect the amount
  39. * of data that has (or would have) been written.
  40. *
  41. * \note Call this function with *dlen = 0 to obtain the
  42. * required buffer size in *dlen
  43. */
  44. int base64_decode( unsigned char *dst, int *dlen,
  45. unsigned char *src, int slen );
  46. /**
  47. * \brief Checkup routine
  48. *
  49. * \return 0 if successful, or 1 if the test failed
  50. */
  51. int base64_self_test( int verbose );
  52. #ifdef __cplusplus
  53. }
  54. #endif
  55. @interface Base64 : NSObject
  56. + (NSData *)decodeString:(NSString *)string;
  57. @end
  58. #endif /* base64.h */