Advertisement
Guest User

b64 header

a guest
Mar 24th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. #ifndef APR_BASE64_H
  2. 25 #define APR_BASE64_H
  3. 26
  4. 27 #include "apu.h"
  5. 28 #include "apr_general.h"
  6. 29
  7. 30 #ifdef __cplusplus
  8. 31 extern "C" {
  9. 32 #endif
  10. 33
  11. 34 /**
  12. 35 * @defgroup APR_Util_Base64 Base64 Encoding
  13. 36 * @ingroup APR
  14. 37 * @{
  15. 38 */
  16. 39
  17. 40 /* Simple BASE64 encode/decode functions.
  18. 41 *
  19. 42 * As we might encode binary strings, hence we require the length of
  20. 43 * the incoming plain source. And return the length of what we decoded.
  21. 44 *
  22. 45 * The decoding function takes any non valid char (i.e. whitespace, \0
  23. 46 * or anything non A-Z,0-9 etc) as terminal.
  24. 47 *
  25. 48 * The handling of terminating \0 characters differs from function to
  26. 49 * function.
  27. 50 *
  28. 51 */
  29. 52
  30. 53 /**
  31. 54 * Given the length of an un-encoded string, get the length of the
  32. 55 * encoded string.
  33. 56 * @param len the length of an unencoded string.
  34. 57 * @return the length of the string after it is encoded, including the
  35. 58 * trailing \0
  36. 59 */
  37. 60 APR_DECLARE(int) apr_base64_encode_len(int len) __attribute__((pure));
  38. 61
  39. 62 /**
  40. 63 * Encode a text string using base64encoding. On EBCDIC machines, the input
  41. 64 * is first converted to ASCII.
  42. 65 * @param coded_dst The destination string for the encoded string. A \0 is
  43. 66 * appended.
  44. 67 * @param plain_src The original string in plain text
  45. 68 * @param len_plain_src The length of the plain text string
  46. 69 * @return the length of the encoded string, including the trailing \0
  47. 70 */
  48. 71 APR_DECLARE(int) apr_base64_encode(char * coded_dst, const char *plain_src,
  49. 72 int len_plain_src)
  50. 73 __attribute__((nonnull(1,2)));
  51. 74
  52. 75 /**
  53. 76 * Encode an text string using base64encoding. This is the same as
  54. 77 * apr_base64_encode() except on EBCDIC machines, where the conversion of the
  55. 78 * input to ASCII is left out.
  56. 79 * @param coded_dst The destination string for the encoded string. A \0 is
  57. 80 * appended.
  58. 81 * @param plain_src The original string in plain text
  59. 82 * @param len_plain_src The length of the plain text string
  60. 83 * @return the length of the encoded string, including the trailing \0
  61. 84 */
  62. 85 APR_DECLARE(int) apr_base64_encode_binary(char * coded_dst,
  63. 86 const unsigned char *plain_src,
  64. 87 int len_plain_src)
  65. 88 __attribute__((nonnull(1,2)));
  66. 89
  67. 90 /**
  68. 91 * Encode a string into memory allocated from a pool in base 64 format
  69. 92 * @param p The pool to allocate from
  70. 93 * @param string The plaintext string
  71. 94 * @return The encoded string
  72. 95 */
  73. 96 APR_DECLARE(char *) apr_pbase64_encode(apr_pool_t *p, const char *string)
  74. 97 __attribute__((nonnull(1,2)));
  75. 98
  76. 99 /**
  77. 100 * Determine the maximum buffer length required to decode the plain text
  78. 101 * string given the encoded string.
  79. 102 * @param coded_src The encoded string
  80. 103 * @return the maximum required buffer length for the plain text string
  81. 104 */
  82. 105 APR_DECLARE(int) apr_base64_decode_len(const char * coded_src)
  83. 106 __attribute__((nonnull(1))) __attribute__((pure));
  84. 107
  85. 108 /**
  86. 109 * Decode a string to plain text. On EBCDIC machines, the result is then
  87. 110 * converted to EBCDIC.
  88. 111 * @param plain_dst The destination string for the plain text. A \0 is
  89. 112 * appended.
  90. 113 * @param coded_src The encoded string
  91. 114 * @return the length of the plain text string (excluding the trailing \0)
  92. 115 */
  93. 116 APR_DECLARE(int) apr_base64_decode(char * plain_dst, const char *coded_src)
  94. 117 __attribute__((nonnull(1,2)));
  95. 118
  96. 119 /**
  97. 120 * Decode an string to plain text. This is the same as apr_base64_decode()
  98. 121 * except no \0 is appended and on EBCDIC machines, the conversion of the
  99. 122 * output to EBCDIC is left out.
  100. 123 * @param plain_dst The destination string for the plain text. The string is
  101. 124 * not \0-terminated.
  102. 125 * @param coded_src The encoded string
  103. 126 * @return the length of the plain text string
  104. 127 */
  105. 128 APR_DECLARE(int) apr_base64_decode_binary(unsigned char * plain_dst,
  106. 129 const char *coded_src)
  107. 130 __attribute__((nonnull(1,2)));
  108. 131
  109. 132 /**
  110. 133 * Decode a base64 encoded string into memory allocated from a pool
  111. 134 * @param p The pool to allocate from
  112. 135 * @param bufcoded The encoded string
  113. 136 * @return The decoded string
  114. 137 */
  115. 138 APR_DECLARE(char *) apr_pbase64_decode(apr_pool_t *p, const char *bufcoded)
  116. 139 __attribute__((nonnull(1,2)));
  117. 140
  118. 141 /** @} */
  119. 142 #ifdef __cplusplus
  120. 143 }
  121. 144 #endif
  122. 145
  123. 146 #endif /* !APR_BASE64_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement