libbase64.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. struct ssse3_base64_state {
  6. int eof;
  7. int bytes;
  8. unsigned char carry;
  9. };
  10. /* Wrapper function to encode a plain string of given length. Output is written
  11. * to *out without trailing zero. Output length in bytes is written to *outlen.
  12. * The buffer in `out` has been allocated by the caller and is at least 4/3 the
  13. * size of the input. See above for `flags`; set to 0 for default operation: */
  14. void ssse3_base64_encode
  15. ( const char *src
  16. , size_t srclen
  17. , char *out
  18. , size_t *outlen
  19. ) ;
  20. /* Call this before calling base64_stream_encode() to init the state. See above
  21. * for `flags`; set to 0 for default operation: */
  22. void ssse3_base64_stream_encode_init
  23. ( struct ssse3_base64_state *state
  24. ) ;
  25. /* Encodes the block of data of given length at `src`, into the buffer at
  26. * `out`. Caller is responsible for allocating a large enough out-buffer; it
  27. * must be at least 4/3 the size of the in-buffer, but take some margin. Places
  28. * the number of new bytes written into `outlen` (which is set to zero when the
  29. * function starts). Does not zero-terminate or finalize the output. */
  30. void ssse3_base64_stream_encode
  31. ( struct ssse3_base64_state *state
  32. , const char *src
  33. , size_t srclen
  34. , char *out
  35. , size_t *outlen
  36. ) ;
  37. /* Finalizes the output begun by previous calls to `base64_stream_encode()`.
  38. * Adds the required end-of-stream markers if appropriate. `outlen` is modified
  39. * and will contain the number of new bytes written at `out` (which will quite
  40. * often be zero). */
  41. void ssse3_base64_stream_encode_final
  42. ( struct ssse3_base64_state *state
  43. , char *out
  44. , size_t *outlen
  45. ) ;
  46. /* Wrapper function to decode a plain string of given length. Output is written
  47. * to *out without trailing zero. Output length in bytes is written to *outlen.
  48. * The buffer in `out` has been allocated by the caller and is at least 3/4 the
  49. * size of the input. See above for `flags`, set to 0 for default operation: */
  50. int ssse3_base64_decode
  51. ( const char *src
  52. , size_t srclen
  53. , char *out
  54. , size_t *outlen
  55. ) ;
  56. /* Call this before calling base64_stream_decode() to init the state. See above
  57. * for `flags`; set to 0 for default operation: */
  58. void ssse3_base64_stream_decode_init
  59. ( struct ssse3_base64_state *state
  60. ) ;
  61. /* Decodes the block of data of given length at `src`, into the buffer at
  62. * `out`. Caller is responsible for allocating a large enough out-buffer; it
  63. * must be at least 3/4 the size of the in-buffer, but take some margin. Places
  64. * the number of new bytes written into `outlen` (which is set to zero when the
  65. * function starts). Does not zero-terminate the output. Returns 1 if all is
  66. * well, and 0 if a decoding error was found, such as an invalid character.
  67. * Returns -1 if the chosen codec is not included in the current build. Used by
  68. * the test harness to check whether a codec is available for testing. */
  69. int ssse3_base64_stream_decode
  70. ( struct ssse3_base64_state *state
  71. , const char *src
  72. , size_t srclen
  73. , char *out
  74. , size_t *outlen
  75. ) ;
  76. #ifdef __cplusplus
  77. }
  78. #endif