Base64.h.in 4.4 KB

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