codecs.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <stdint.h>
  2. #include <stddef.h>
  3. #include "../include/libbase64.h"
  4. #include "config.h"
  5. // Function parameters for encoding functions:
  6. #define BASE64_ENC_PARAMS \
  7. ( struct base64_state *state \
  8. , const char *src \
  9. , size_t srclen \
  10. , char *out \
  11. , size_t *outlen \
  12. )
  13. // Function parameters for decoding functions:
  14. #define BASE64_DEC_PARAMS \
  15. ( struct base64_state *state \
  16. , const char *src \
  17. , size_t srclen \
  18. , char *out \
  19. , size_t *outlen \
  20. )
  21. // Function signature for encoding functions:
  22. #define BASE64_ENC_FUNCTION(arch) \
  23. void \
  24. base64_stream_encode_ ## arch \
  25. BASE64_ENC_PARAMS
  26. // Function signature for decoding functions:
  27. #define BASE64_DEC_FUNCTION(arch) \
  28. int \
  29. base64_stream_decode_ ## arch \
  30. BASE64_DEC_PARAMS
  31. // Cast away unused variable, silence compiler:
  32. #define UNUSED(x) ((void)(x))
  33. // Stub function when encoder arch unsupported:
  34. #define BASE64_ENC_STUB \
  35. UNUSED(state); \
  36. UNUSED(src); \
  37. UNUSED(srclen); \
  38. UNUSED(out); \
  39. \
  40. *outlen = 0;
  41. // Stub function when decoder arch unsupported:
  42. #define BASE64_DEC_STUB \
  43. UNUSED(state); \
  44. UNUSED(src); \
  45. UNUSED(srclen); \
  46. UNUSED(out); \
  47. UNUSED(outlen); \
  48. \
  49. return -1;
  50. struct codec
  51. {
  52. void (* enc) BASE64_ENC_PARAMS;
  53. int (* dec) BASE64_DEC_PARAMS;
  54. };
  55. extern void codec_choose (struct codec *, int flags);