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