Base64.h.in 4.5 KB

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