Base64.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
  3. #ifndef cmsys_Base64_h
  4. #define cmsys_Base64_h
  5. #include <cmsys/Configure.h>
  6. #include <stddef.h> /* size_t */
  7. /* Redefine all public interface symbol names to be in the proper
  8. namespace. These macros are used internally to kwsys only, and are
  9. not visible to user code. Use kwsysHeaderDump.pl to reproduce
  10. these macros after making changes to the interface. */
  11. #if !defined(KWSYS_NAMESPACE)
  12. #define kwsys_ns(x) cmsys##x
  13. #define kwsysEXPORT cmsys_EXPORT
  14. #endif
  15. #if !cmsys_NAME_IS_KWSYS
  16. #define kwsysBase64 kwsys_ns(Base64)
  17. #define kwsysBase64_Decode kwsys_ns(Base64_Decode)
  18. #define kwsysBase64_Decode3 kwsys_ns(Base64_Decode3)
  19. #define kwsysBase64_Encode kwsys_ns(Base64_Encode)
  20. #define kwsysBase64_Encode1 kwsys_ns(Base64_Encode1)
  21. #define kwsysBase64_Encode2 kwsys_ns(Base64_Encode2)
  22. #define kwsysBase64_Encode3 kwsys_ns(Base64_Encode3)
  23. #endif
  24. #if defined(__cplusplus)
  25. extern "C" {
  26. #endif
  27. /**
  28. * Encode 3 bytes into a 4 byte string.
  29. */
  30. kwsysEXPORT void kwsysBase64_Encode3(const unsigned char* src,
  31. unsigned char* dest);
  32. /**
  33. * Encode 2 bytes into a 4 byte string.
  34. */
  35. kwsysEXPORT void kwsysBase64_Encode2(const unsigned char* src,
  36. unsigned char* dest);
  37. /**
  38. * Encode 1 bytes into a 4 byte string.
  39. */
  40. kwsysEXPORT void kwsysBase64_Encode1(const unsigned char* src,
  41. unsigned char* dest);
  42. /**
  43. * Encode 'length' bytes from the input buffer and store the encoded
  44. * stream into the output buffer. Return the length of the encoded
  45. * buffer (output). Note that the output buffer must be allocated by
  46. * the caller (length * 1.5 should be a safe estimate). If 'mark_end'
  47. * is true than an extra set of 4 bytes is added to the end of the
  48. * stream if the input is a multiple of 3 bytes. These bytes are
  49. * invalid chars and therefore they will stop the decoder thus
  50. * enabling the caller to decode a stream without actually knowing how
  51. * much data to expect (if the input is not a multiple of 3 bytes then
  52. * the extra padding needed to complete the encode 4 bytes will stop
  53. * the decoding anyway).
  54. */
  55. kwsysEXPORT size_t kwsysBase64_Encode(const unsigned char* input,
  56. size_t length, unsigned char* output,
  57. int mark_end);
  58. /**
  59. * Decode 4 bytes into a 3 byte string. Returns the number of bytes
  60. * actually decoded.
  61. */
  62. kwsysEXPORT int kwsysBase64_Decode3(const unsigned char* src,
  63. unsigned char* dest);
  64. /**
  65. * Decode bytes from the input buffer and store the decoded stream
  66. * into the output buffer until 'length' bytes have been decoded.
  67. * Return the real length of the decoded stream (which should be equal
  68. * to 'length'). Note that the output buffer must be allocated by the
  69. * caller. If 'max_input_length' is not null, then it specifies the
  70. * number of encoded bytes that should be at most read from the input
  71. * buffer. In that case the 'length' parameter is ignored. This
  72. * enables the caller to decode a stream without actually knowing how
  73. * much decoded data to expect (of course, the buffer must be large
  74. * enough).
  75. */
  76. kwsysEXPORT size_t kwsysBase64_Decode(const unsigned char* input,
  77. size_t length, unsigned char* output,
  78. size_t max_input_length);
  79. #if defined(__cplusplus)
  80. } /* extern "C" */
  81. #endif
  82. /* If we are building a kwsys .c or .cxx file, let it use these macros.
  83. Otherwise, undefine them to keep the namespace clean. */
  84. #if !defined(KWSYS_NAMESPACE)
  85. #undef kwsys_ns
  86. #undef kwsysEXPORT
  87. #if !cmsys_NAME_IS_KWSYS
  88. #undef kwsysBase64
  89. #undef kwsysBase64_Decode
  90. #undef kwsysBase64_Decode3
  91. #undef kwsysBase64_Encode
  92. #undef kwsysBase64_Encode1
  93. #undef kwsysBase64_Encode2
  94. #undef kwsysBase64_Encode3
  95. #endif
  96. #endif
  97. #endif