apr_encode.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file apr_encode.h
  18. * @brief APR-UTIL Encoding
  19. */
  20. #ifndef APR_ENCODE_H
  21. #define APR_ENCODE_H
  22. #include "apr.h"
  23. #include "apr_general.h"
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /**
  28. * @defgroup APR_Util_Encode Base64/Base64Url/Base32/Base32Hex/Base16 Encoding
  29. * @ingroup APR_Util
  30. * @{
  31. */
  32. /**
  33. * RFC4648 and RFC7515 compliant BASE64, BASE64URL, BASE32, BASE32HEX
  34. * and BASE16 encode/decode functions.
  35. *
  36. * The following encodings are supported:
  37. *
  38. * - Base 64 Encoding
  39. *
  40. * o Use flag APR_ENCODE_NONE
  41. * o https://tools.ietf.org/html/rfc4648#section-4
  42. *
  43. * - Base 64 Encoding with URL and Filename Safe Alphabet
  44. *
  45. * o Use flag APR_ENCODE_URL
  46. * o https://tools.ietf.org/html/rfc4648#section-5
  47. *
  48. * - Base 64 URL Encoding without Padding
  49. *
  50. * o Use flag APR_ENCODE_BASE64URL
  51. * o https://tools.ietf.org/html/rfc7515#appendix-C
  52. *
  53. * - Base 32 Encoding
  54. *
  55. * o Use flag APR_ENCODE_NONE
  56. * o https://tools.ietf.org/html/rfc4648#section-6
  57. *
  58. * - Base 32 Encoding with Extended Hex Alphabet
  59. *
  60. * o Use flag APR_ENCODE_BASE32HEX
  61. * o https://tools.ietf.org/html/rfc4648#section-7
  62. *
  63. * - Base 16 Encoding
  64. *
  65. * o Use flags APR_ENCODE_NONE/APR_ENCODE_COLON
  66. * o https://tools.ietf.org/html/rfc4648#section-8
  67. *
  68. * If a non valid character of any kind including whitespace is passed to any
  69. * of the decoder functions, APR_BADCH will be returned. In this case decoding
  70. * will still take place, but the results can not be trusted.
  71. *
  72. * If APR_ENCODE_RELAXED is passed to the decoder functions, decoding will be
  73. * attempted up until the first non valid character. If this results in an
  74. * invalid state in the decoder, such as but not limited to an odd number of
  75. * base16 characters, APR_BADCH will still be returned.
  76. *
  77. * If APR_ENCODE_RELAXED is not passed to a decoder function, the decoding will
  78. * be done in constant time regardless of whether the result returns APR_SUCCESS
  79. * or APR_BADCH.
  80. *
  81. * If the dest parameter is NULL, the maximum theoretical buffer size is
  82. * returned in the len field, including space for a terminating zero character
  83. * if the destination is a string. This value can be used to allocate buffers
  84. * of a suitable safe size.
  85. *
  86. * If the dest parameter is provided, the encoding or decoding will take place,
  87. * and the actual number of characters written is returned in the len field,
  88. * ignoring any terminating zero.
  89. *
  90. * Plain strings are not assumed '\0' terminated unless APR_ENCODE_STRING is
  91. * provided.
  92. *
  93. */
  94. /**
  95. * When passing a string to one of the encode functions, this value can be
  96. * passed to indicate a string-valued key, and have the length computed
  97. * automatically.
  98. */
  99. #define APR_ENCODE_STRING (-1)
  100. /**
  101. * Generate RFC4648 base16/base32/base64.
  102. */
  103. #define APR_ENCODE_NONE 0
  104. /**
  105. * If relaxed, decode up until the first non base16/base32/base64 character.
  106. */
  107. #define APR_ENCODE_RELAXED 1
  108. /**
  109. * Omit the padding character (=) while encoding.
  110. */
  111. #define APR_ENCODE_NOPADDING 2
  112. /**
  113. * Generate RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet
  114. */
  115. #define APR_ENCODE_URL 4
  116. /**
  117. * Generate RFC7515 BASE64URL
  118. */
  119. #define APR_ENCODE_BASE64URL (APR_ENCODE_NOPADDING | APR_ENCODE_URL)
  120. /**
  121. * Generate base32hex encoding instead of base32 encoding
  122. */
  123. #define APR_ENCODE_BASE32HEX 8
  124. /**
  125. * Generate base16 with colons between each token.
  126. */
  127. #define APR_ENCODE_COLON 16
  128. /**
  129. * Generate base16 with lower case characters.
  130. */
  131. #define APR_ENCODE_LOWER 32
  132. /**
  133. * Convert text data to base64.
  134. * @param dest The destination string, can be NULL.
  135. * @param src The original string.
  136. * @param slen The length of the original string, or APR_ENCODE_STRING if
  137. * NUL terminated.
  138. * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 64 Encoding. If
  139. * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_URL,
  140. * use RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet.
  141. * If APR_ENCODE_BASE64URL, use RFC7515 base64url Encoding.
  142. * @param len If present and src is NULL, returns the maximum possible length
  143. * of the destination string, including a zero pad. If present and src is
  144. * not NULL, returns the number of characters actually written.
  145. * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL.
  146. */
  147. APR_DECLARE(apr_status_t) apr_encode_base64(char *dest, const char *src,
  148. apr_ssize_t slen, int flags, apr_size_t * len);
  149. /**
  150. * Convert binary data to base64.
  151. * @param dest The destination string, can be NULL.
  152. * @param src The original buffer.
  153. * @param slen The length of the original buffer.
  154. * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 64 Encoding. If
  155. * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_URL,
  156. * use RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet.
  157. * If APR_ENCODE_BASE64URL, use RFC7515 base64url Encoding.
  158. * @param len If present and src is NULL, returns the maximum possible length
  159. * of the destination string, including a zero pad. If present and src is
  160. * not NULL, returns the number of characters actually written.
  161. * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL.
  162. */
  163. APR_DECLARE(apr_status_t) apr_encode_base64_binary(char *dest, const unsigned char *src,
  164. apr_ssize_t slen, int flags, apr_size_t * len);
  165. /**
  166. * Convert text data to base64, and return the results from a pool.
  167. * @param p Pool to allocate from.
  168. * @param src The original string.
  169. * @param slen The length of the original string, or APR_ENCODE_STRING if
  170. * NUL terminated.
  171. * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 64 Encoding. If
  172. * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_URL,
  173. * use RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet.
  174. * If APR_ENCODE_BASE64URL, use RFC7515 base64url Encoding.
  175. * @param len If present, returns the number of characters written excluding
  176. * the zero pad.
  177. * @return A zero padded string allocated from the pool on success, or
  178. * NULL if src was NULL.
  179. */
  180. APR_DECLARE(const char *)apr_pencode_base64(apr_pool_t * p, const char *src,
  181. apr_ssize_t slen, int flags, apr_size_t * len)__attribute__((nonnull(1)));
  182. /**
  183. * Convert binary data to base64, and return the results from a pool.
  184. * @param p Pool to allocate from.
  185. * @param src The original buffer.
  186. * @param slen The length of the original buffer.
  187. * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 64 Encoding. If
  188. * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_URL,
  189. * use RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet.
  190. * If APR_ENCODE_BASE64URL, use RFC7515 base64url Encoding.
  191. * @param len If present, returns the number of characters written excluding
  192. * the zero pad.
  193. * @return A zero padded string allocated from the pool on success, or
  194. * NULL if src was NULL.
  195. */
  196. APR_DECLARE(const char *)apr_pencode_base64_binary(apr_pool_t * p, const unsigned char *src,
  197. apr_ssize_t slen, int flags, apr_size_t * len)__attribute__((nonnull(1)));
  198. /**
  199. * Convert base64 or base64url with or without padding to text data.
  200. * @param dest The destination string, can be NULL.
  201. * @param src The original string.
  202. * @param slen The length of the original string, or APR_ENCODE_STRING if
  203. * NUL terminated.
  204. * @param flags If APR_ENCODE_NONE, attempt to decode the full original buffer,
  205. * and return NULL if any bad character is detected. If APR_ENCODE_RELAXED,
  206. * decode until the first non base64/base64url character.
  207. * @param len If present and src is NULL, returns the maximum possible length
  208. * of the destination string, including a zero pad. If present and src is
  209. * not NULL, returns the number of characters actually written.
  210. * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL, or APR_BADCH
  211. * if a non hex character is present.
  212. */
  213. APR_DECLARE(apr_status_t) apr_decode_base64(char *dest, const char *src,
  214. apr_ssize_t slen, int flags, apr_size_t * len);
  215. /**
  216. * Convert base64 or base64url with or without padding to binary data.
  217. * @param dest The destination buffer, can be NULL.
  218. * @param src The original string.
  219. * @param slen The length of the original string, or APR_ENCODE_STRING if
  220. * NUL terminated.
  221. * @param flags If APR_ENCODE_NONE, attempt to decode the full original buffer,
  222. * and return NULL if any bad character is detected. If APR_ENCODE_RELAXED,
  223. * decode until the first non base64/base64url character.
  224. * @param len If present and src is NULL, returns the maximum possible length
  225. * of the destination buffer, including a zero pad. If present and src is
  226. * not NULL, returns the number of characters actually written.
  227. * @return APR_SUCCESS, or APR_NOTFOUND if the src was NULL, or APR_BADCH
  228. * if a non base64 character is present.
  229. */
  230. APR_DECLARE(apr_status_t) apr_decode_base64_binary(unsigned char *dest,
  231. const char *src, apr_ssize_t slen, int flags, apr_size_t * len);
  232. /**
  233. * Convert base64 or base64url with or without padding to text data, and
  234. * return the results from a pool.
  235. * @param p Pool to allocate from.
  236. * @param src The base64 string to decode.
  237. * @param slen The length of the base64 string, or APR_ENCODE_STRING if
  238. * NUL terminated.
  239. * @param flags If APR_ENCODE_NONE, attempt to decode the full original buffer,
  240. * and return NULL if any bad character is detected. If APR_ENCODE_RELAXED,
  241. * decode until the first non base64/base64url character.
  242. * @param len If present, returns the number of characters written, excluding
  243. * the zero padding.
  244. * @return A string allocated from the pool containing the result with a zero
  245. * pad. If src was NULL, or an error occurred, NULL is returned.
  246. */
  247. APR_DECLARE(const char *)apr_pdecode_base64(apr_pool_t * p, const char *src,
  248. apr_ssize_t slen, int flags, apr_size_t * len)
  249. __attribute__((nonnull(1)));
  250. /**
  251. * Convert base64 or base64url with or without padding to binary data, and
  252. * return the results from a pool.
  253. * @param p Pool to allocate from.
  254. * @param src The original string.
  255. * @param slen The length of the original string, or APR_ENCODE_STRING if
  256. * NUL terminated.
  257. * @param flags If APR_ENCODE_NONE, attempt to decode the full original buffer,
  258. * and return NULL if any bad character is detected. If APR_ENCODE_RELAXED,
  259. * decode until the first non base64/base64url character.
  260. * @param len If present, returns the number of characters written, excluding
  261. * the zero padding.
  262. * @return A buffer allocated from the pool containing the result with a zero
  263. * pad. If src was NULL, or an error occurred, NULL is returned.
  264. */
  265. APR_DECLARE(const unsigned char *)apr_pdecode_base64_binary(apr_pool_t * p,
  266. const char *src, apr_ssize_t slen, int flags, apr_size_t * len)
  267. __attribute__((nonnull(1)));
  268. /**
  269. * Convert text data to base32.
  270. * @param dest The destination string, can be NULL.
  271. * @param src The original string.
  272. * @param slen The length of the original string, or APR_ENCODE_STRING if
  273. * NUL terminated.
  274. * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 32 Encoding. If
  275. * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_BASE32HEX,
  276. * use RFC4648 base32hex Encoding.
  277. * @param len If present and src is NULL, returns the maximum possible length
  278. * of the destination string, including a zero pad. If present and src is
  279. * not NULL, returns the number of characters actually written.
  280. * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL.
  281. */
  282. APR_DECLARE(apr_status_t) apr_encode_base32(char *dest, const char *src,
  283. apr_ssize_t slen, int flags, apr_size_t * len);
  284. /**
  285. * Convert binary data to base32.
  286. * @param dest The destination string, can be NULL.
  287. * @param src The original buffer.
  288. * @param slen The length of the original buffer.
  289. * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 32 Encoding. If
  290. * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_BASE32HEX,
  291. * use RFC4648 base32hex Encoding.
  292. * @param len If present and src is NULL, returns the maximum possible length
  293. * of the destination string, including a zero pad. If present and src is
  294. * not NULL, returns the number of characters actually written.
  295. * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL.
  296. */
  297. APR_DECLARE(apr_status_t) apr_encode_base32_binary(char *dest, const unsigned char *src,
  298. apr_ssize_t slen, int flags, apr_size_t * len);
  299. /**
  300. * Convert text data to base32, and return the results from a pool.
  301. * @param p Pool to allocate from.
  302. * @param src The original string.
  303. * @param slen The length of the original string, or APR_ENCODE_STRING if
  304. * NUL terminated.
  305. * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 32 Encoding. If
  306. * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_BASE32HEX,
  307. * use RFC4648 base32hex Encoding.
  308. * @param len If present, returns the number of characters written excluding
  309. * the zero pad.
  310. * @return A zero padded string allocated from the pool on success, or
  311. * NULL if src was NULL.
  312. */
  313. APR_DECLARE(const char *)apr_pencode_base32(apr_pool_t * p, const char *src,
  314. apr_ssize_t slen, int flags, apr_size_t * len)
  315. __attribute__((nonnull(1)));
  316. /**
  317. * Convert binary data to base32, and return the results from a pool.
  318. * @param p Pool to allocate from.
  319. * @param src The original buffer.
  320. * @param slen The length of the original buffer.
  321. * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 32 Encoding. If
  322. * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_BASE32HEX,
  323. * use RFC7515 base32hex Encoding.
  324. * @param len If present, returns the number of characters written excluding
  325. * the zero pad.
  326. * @return A zero padded string allocated from the pool on success, or
  327. * NULL if src was NULL.
  328. */
  329. APR_DECLARE(const char *)apr_pencode_base32_binary(apr_pool_t * p, const unsigned char *src,
  330. apr_ssize_t slen, int flags, apr_size_t * len)
  331. __attribute__((nonnull(1)));
  332. /**
  333. * Convert base32 or base32hex with or without padding to text data.
  334. * @param dest The destination string, can be NULL.
  335. * @param src The original string.
  336. * @param slen The length of the original string, or APR_ENCODE_STRING if
  337. * NUL terminated.
  338. * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 32 Encoding. If
  339. * APR_ENCODE_BASE32HEX, use RFC4648 base32hex Encoding.
  340. * @param len If present and src is NULL, returns the maximum possible length
  341. * of the destination buffer, including a zero pad. If present and src is
  342. * not NULL, returns the number of characters actually written.
  343. * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL, or APR_BADCH
  344. * if a non base32 character is present.
  345. */
  346. APR_DECLARE(apr_status_t) apr_decode_base32(char *dest, const char *src,
  347. apr_ssize_t slen, int flags, apr_size_t * len);
  348. /**
  349. * Convert base32 or base32hex with or without padding to binary data.
  350. * @param dest The destination buffer, can be NULL.
  351. * @param src The original string.
  352. * @param slen The length of the original string, or APR_ENCODE_STRING if
  353. * NUL terminated.
  354. * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 32 Encoding. If
  355. * APR_ENCODE_BASE32HEX, use RFC4648 base32hex Encoding.
  356. * @param len If present and src is NULL, returns the maximum possible length
  357. * of the destination buffer, including a zero pad. If present and src is
  358. * not NULL, returns the number of characters actually written.
  359. * @return APR_SUCCESS, or APR_NOTFOUND if the src was NULL, or APR_BADCH
  360. * if a non base32 character is present.
  361. */
  362. APR_DECLARE(apr_status_t) apr_decode_base32_binary(unsigned char *dest,
  363. const char *src, apr_ssize_t slen, int flags, apr_size_t * len);
  364. /**
  365. * Convert base32 or base32hex with or without padding to text data, and
  366. * return the results from a pool.
  367. * @param p Pool to allocate from.
  368. * @param src The base32 string to decode.
  369. * @param slen The length of the base32 string, or APR_ENCODE_STRING if
  370. * NUL terminated.
  371. * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 32 Encoding. If
  372. * APR_ENCODE_BASE32HEX, use RFC4648 base32hex Encoding.
  373. * @param len If present, returns the number of characters written, excluding
  374. * the zero padding.
  375. * @return A string allocated from the pool containing the result with a zero
  376. * pad. If src was NULL, or an error occurred, NULL is returned.
  377. */
  378. APR_DECLARE(const char *)apr_pdecode_base32(apr_pool_t * p, const char *src,
  379. apr_ssize_t slen, int flags, apr_size_t * len)
  380. __attribute__((nonnull(1)));
  381. /**
  382. * Convert base32 or base32hex with or without padding to binary data, and
  383. * return the results from a pool.
  384. * @param p Pool to allocate from.
  385. * @param src The original string.
  386. * @param slen The length of the original string, or APR_ENCODE_STRING if
  387. * NUL terminated.
  388. * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 32 Encoding. If
  389. * APR_ENCODE_BASE32HEX, use RFC4648 base32hex Encoding.
  390. * @param len If present, returns the number of characters written, excluding
  391. * the zero padding.
  392. * @return A buffer allocated from the pool containing the result with a zero
  393. * pad. If src was NULL, or an error occurred, NULL is returned.
  394. */
  395. APR_DECLARE(const unsigned char *)apr_pdecode_base32_binary(apr_pool_t * p,
  396. const char *src, apr_ssize_t slen, int flags, apr_size_t * len)
  397. __attribute__((nonnull(1)));
  398. /**
  399. * Convert text data to base16 (hex).
  400. * @param dest The destination string, can be NULL.
  401. * @param src The original string.
  402. * @param slen The length of the original string, or APR_ENCODE_STRING if
  403. * NUL terminated.
  404. * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 16 Encoding. If
  405. * APR_ENCODE_COLON, separate each token with a colon.
  406. * @param len If present and src is NULL, returns the maximum possible length
  407. * of the destination buffer, including a zero pad. If present and src is
  408. * not NULL, returns the number of characters actually written.
  409. * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL.
  410. */
  411. APR_DECLARE(apr_status_t) apr_encode_base16(char *dest, const char *src,
  412. apr_ssize_t slen, int flags, apr_size_t * len);
  413. /**
  414. * Convert binary data to base16 (hex).
  415. * @param dest The destination string, can be NULL.
  416. * @param src The original buffer.
  417. * @param slen The length of the original buffer.
  418. * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 16 Encoding. If
  419. * APR_ENCODE_COLON, separate each token with a colon.
  420. * @param len If present and src is NULL, returns the maximum possible length
  421. * of the destination buffer, including a zero pad. If present and src is
  422. * not NULL, returns the number of characters actually written.
  423. * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL.
  424. */
  425. APR_DECLARE(apr_status_t) apr_encode_base16_binary(char *dest,
  426. const unsigned char *src, apr_ssize_t slen, int flags,
  427. apr_size_t * len);
  428. /**
  429. * Convert text data to base16 (hex), and return the results from a
  430. * pool.
  431. * @param p Pool to allocate from.
  432. * @param src The original string.
  433. * @param slen The length of the original string, or APR_ENCODE_STRING if
  434. * NUL terminated.
  435. * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 16 Encoding. If
  436. * APR_ENCODE_COLON, separate each token with a colon.
  437. * @param len If present, returns the number of characters written, excluding
  438. * the zero padding.
  439. * @return A string allocated from the pool containing the result with a zero
  440. * pad. If src was NULL, or an error occurred, NULL is returned.
  441. */
  442. APR_DECLARE(const char *)apr_pencode_base16(apr_pool_t * p, const char *src,
  443. apr_ssize_t slen, int flags, apr_size_t * len)
  444. __attribute__((nonnull(1)));
  445. /**
  446. * Convert binary data to base16 (hex), and return the results from a
  447. * pool.
  448. * @param p Pool to allocate from.
  449. * @param src The original buffer.
  450. * @param slen The length of the original buffer.
  451. * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 16 Encoding. If
  452. * APR_ENCODE_COLON, separate each token with a colon.
  453. * @param len If present, returns the number of characters written, excluding
  454. * the zero padding.
  455. * @return A string allocated from the pool containing the result with a zero
  456. * pad. If src was NULL, or an error occurred, NULL is returned.
  457. */
  458. APR_DECLARE(const char *)apr_pencode_base16_binary(apr_pool_t * p,
  459. const unsigned char *src, apr_ssize_t slen,
  460. int flags, apr_size_t * len)__attribute__((nonnull(1)));
  461. /**
  462. * Convert base16 (hex) to text data.
  463. * @param dest The destination string, can be NULL.
  464. * @param src The original string.
  465. * @param slen The length of the original string, or APR_ENCODE_STRING if
  466. * NUL terminated.
  467. * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 16 Encoding. If
  468. * APR_ENCODE_COLON, allow tokens to be separated with a colon.
  469. * @param len If present and src is NULL, returns the maximum possible length
  470. * of the destination buffer, including a zero pad. If present and src is
  471. * not NULL, returns the number of characters actually written.
  472. * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL, or APR_BADCH
  473. * if a non hex character is present. A zero pad is appended to the buffer.
  474. */
  475. APR_DECLARE(apr_status_t) apr_decode_base16(char *dest, const char *src,
  476. apr_ssize_t slen, int flags, apr_size_t * len);
  477. /**
  478. * Convert base16 (hex) to binary data.
  479. * @param dest The destination buffer, can be NULL.
  480. * @param src The original string.
  481. * @param slen The length of the original string, or APR_ENCODE_STRING if
  482. * NUL terminated.
  483. * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 16 Encoding. If
  484. * APR_ENCODE_COLON, allow tokens to be separated with a colon.
  485. * @param len If present and src is NULL, returns the maximum possible length
  486. * of the destination buffer, including a zero pad. If present and src is
  487. * not NULL, returns the number of characters actually written.
  488. * @return APR_SUCCESS, or APR_NOTFOUND if the string was NULL, or APR_BADCH
  489. * if a non hex character is present. No zero pad is written to the buffer.
  490. */
  491. APR_DECLARE(apr_status_t) apr_decode_base16_binary(unsigned char *dest,
  492. const char *src, apr_ssize_t slen, int flags, apr_size_t * len);
  493. /**
  494. * Convert base16 (hex) and return the results from a pool.
  495. * @param p Pool to allocate from.
  496. * @param src The original string.
  497. * @param slen The length of the original string, or APR_ENCODE_STRING if
  498. * NUL terminated.
  499. * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 16 Encoding. If
  500. * APR_ENCODE_COLON, allow tokens to be separated with a colon.
  501. * @param len If present, returns the number of characters written, excluding
  502. * the zero padding.
  503. * @return A buffer allocated from the pool containing the result with a zero
  504. * pad. If src was NULL, or an error occurred, NULL is returned.
  505. */
  506. APR_DECLARE(const char *)apr_pdecode_base16(apr_pool_t * p, const char *src,
  507. apr_ssize_t slen, int flags, apr_size_t * len)
  508. __attribute__((nonnull(1)));
  509. /**
  510. * Convert base16 (hex) to binary data, and return the results from a pool.
  511. * @param p Pool to allocate from.
  512. * @param src The original string.
  513. * @param slen The length of the original string, or APR_ENCODE_STRING if
  514. * NUL terminated.
  515. * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 16 Encoding. If
  516. * APR_ENCODE_COLON, allow tokens to be separated with a colon.
  517. * @param len If present, returns the number of characters written, excluding
  518. * the zero padding.
  519. * @return A buffer allocated from the pool containing the result with a zero
  520. * pad. If src was NULL, or an error occurred, NULL is returned.
  521. */
  522. APR_DECLARE(const unsigned char *)apr_pdecode_base16_binary(apr_pool_t * p,
  523. const char *src, apr_ssize_t slen, int flags, apr_size_t * len)
  524. __attribute__((nonnull(1)));
  525. /** @} */
  526. #ifdef __cplusplus
  527. }
  528. #endif
  529. #endif /* !APR_ENCODE_H */