Apache Portable Runtime
Loading...
Searching...
No Matches
apr_encode.h
Go to the documentation of this file.
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/**
18 * @file apr_encode.h
19 * @brief APR-UTIL Encoding
20 */
21#ifndef APR_ENCODE_H
22#define APR_ENCODE_H
23
24#include "apr.h"
25#include "apr_general.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/**
32 * @defgroup APR_Util_Encode Base64/Base64Url/Base32/Base32Hex/Base16 Encoding
33 * @ingroup APR_Util
34 * @{
35 */
36
37/**
38 * RFC4648 and RFC7515 compliant BASE64, BASE64URL, BASE32, BASE32HEX
39 * and BASE16 encode/decode functions.
40 *
41 * The following encodings are supported:
42 *
43 * - Base 64 Encoding
44 *
45 * o Use flag APR_ENCODE_NONE
46 * o https://tools.ietf.org/html/rfc4648#section-4
47 *
48 * - Base 64 Encoding with URL and Filename Safe Alphabet
49 *
50 * o Use flag APR_ENCODE_URL
51 * o https://tools.ietf.org/html/rfc4648#section-5
52 *
53 * - Base 64 URL Encoding without Padding
54 *
55 * o Use flag APR_ENCODE_BASE64URL
56 * o https://tools.ietf.org/html/rfc7515#appendix-C
57 *
58 * - Base 32 Encoding
59 *
60 * o Use flag APR_ENCODE_NONE
61 * o https://tools.ietf.org/html/rfc4648#section-6
62 *
63 * - Base 32 Encoding with Extended Hex Alphabet
64 *
65 * o Use flag APR_ENCODE_BASE32HEX
66 * o https://tools.ietf.org/html/rfc4648#section-7
67 *
68 * - Base 16 Encoding
69 *
70 * o Use flags APR_ENCODE_NONE/APR_ENCODE_COLON
71 * o https://tools.ietf.org/html/rfc4648#section-8
72 *
73 * If a non valid character of any kind including whitespace is passed to any
74 * of the decoder functions, APR_BADCH will be returned. In this case decoding
75 * will still take place, but the results can not be trusted.
76 *
77 * If APR_ENCODE_RELAXED is passed to the decoder functions, decoding will be
78 * attempted up until the first non valid character. If this results in an
79 * invalid state in the decoder, such as but not limited to an odd number of
80 * base16 characters, APR_BADCH will still be returned.
81 *
82 * If APR_ENCODE_RELAXED is not passed to a decoder function, the decoding will
83 * be done in constant time regardless of whether the result returns APR_SUCCESS
84 * or APR_BADCH.
85 *
86 * If the dest parameter is NULL, the maximum theoretical buffer size is
87 * returned in the len field, including space for a terminating zero character
88 * if the destination is a string. This value can be used to allocate buffers
89 * of a suitable safe size.
90 *
91 * If the dest parameter is provided, the encoding or decoding will take place,
92 * and the actual number of characters written is returned in the len field,
93 * ignoring any terminating zero.
94 *
95 * Plain strings are not assumed '\0' terminated unless APR_ENCODE_STRING is
96 * provided.
97 *
98 */
99
100/**
101 * When passing a string to one of the encode functions, this value can be
102 * passed to indicate a string-valued key, and have the length computed
103 * automatically.
104 */
105#define APR_ENCODE_STRING (-1)
106
107/**
108 * Generate RFC4648 base16/base32/base64.
109 */
110#define APR_ENCODE_NONE 0
111
112/**
113 * If relaxed, decode up until the first non base16/base32/base64 character.
114 */
115#define APR_ENCODE_RELAXED 1
116
117/**
118 * Omit the padding character (=) while encoding.
119 */
120#define APR_ENCODE_NOPADDING 2
121
122/**
123 * Generate RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet
124 */
125#define APR_ENCODE_URL 4
126
127/**
128 * Generate RFC7515 BASE64URL
129 */
130#define APR_ENCODE_BASE64URL (APR_ENCODE_NOPADDING | APR_ENCODE_URL)
131
132/**
133 * Generate base32hex encoding instead of base32 encoding
134 */
135#define APR_ENCODE_BASE32HEX 8
136
137/**
138 * Generate base16 with colons between each token.
139 */
140#define APR_ENCODE_COLON 16
141
142/**
143 * Generate base16 with lower case characters.
144 */
145#define APR_ENCODE_LOWER 32
146
147/**
148 * Convert text data to base64.
149 * @param dest The destination string, can be NULL to output in \c len the
150 * needed buffer length for encoding.
151 * @param src The original string, can be NULL if \c dest is NULL and \c slen
152 * is positive or nul.
153 * @param slen The length of the original string, or APR_ENCODE_STRING if
154 * the actual length should be computed based on NUL termination.
155 * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 64 Encoding. If
156 * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_URL,
157 * use RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet.
158 * If APR_ENCODE_BASE64URL, use RFC7515 base64url Encoding.
159 * @param len If not NULL, outputs the length of the buffer needed for encoding
160 * (including the trailing NUL) if \c dest is NULL, or the actual length of
161 * the encoding (excluding the trailing NUL) if \c dest is not NULL.
162 * @return APR_SUCCESS, or APR_EINVAL if \c slen is not APR_ENCODE_STRING and
163 * negative, or APR_NOTFOUND if \c dest is not NULL and \c src is NULL, or
164 * APR_ENOSPC if \c dest is NULL and the source length (based on \c slen or
165 * APR_ENCODE_STRING) is too big to encode.
166 */
167APR_DECLARE(apr_status_t) apr_encode_base64(char *dest, const char *src,
168 apr_ssize_t slen, int flags, apr_size_t * len);
169
170/**
171 * Convert binary data to base64.
172 * @param dest The destination string, can be NULL to output in \c len the
173 * needed buffer length for encoding.
174 * @param src The original buffer, can be NULL if \c dest is NULL.
175 * @param slen The length of the original buffer.
176 * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 64 Encoding. If
177 * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_URL,
178 * use RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet.
179 * If APR_ENCODE_BASE64URL, use RFC7515 base64url Encoding.
180 * @param len If not NULL, outputs the length of the buffer needed for encoding
181 * (including the trailing NUL) if \c dest is NULL, or the actual length of
182 * the encoding (excluding the trailing NUL) if \c dest is not NULL.
183 * @return APR_SUCCESS, or APR_EINVAL if \c slen is negative, or APR_NOTFOUND
184 * if \c dest is not NULL and \c src is NULL, or APR_ENOSPC if \c dest is NULL
185 * and the source length (based on \c slen or APR_ENCODE_STRING) is too big to
186 * encode.
187 */
188APR_DECLARE(apr_status_t) apr_encode_base64_binary(char *dest, const unsigned char *src,
189 apr_ssize_t slen, int flags, apr_size_t * len);
190
191/**
192 * Convert text data to base64, and return the results from a pool.
193 * @param p Pool to allocate from.
194 * @param src The original string.
195 * @param slen The length of the original string, or APR_ENCODE_STRING if
196 * the actual length should be computed based on NUL termination.
197 * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 64 Encoding. If
198 * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_URL,
199 * use RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet.
200 * If APR_ENCODE_BASE64URL, use RFC7515 base64url Encoding.
201 * @param len If not NULL, outputs the length of the encoding (excluding the
202 * trailing NUL).
203 * @return A NUL terminated string allocated from the pool on success,
204 * or NULL if src is NULL or allocation failed or the encoding is not
205 * possible (see apr_encode_base64 errors).
206 */
207APR_DECLARE(const char *)apr_pencode_base64(apr_pool_t * p, const char *src,
208 apr_ssize_t slen, int flags, apr_size_t * len)__attribute__((nonnull(1)));
209
210/**
211 * Convert binary data to base64, and return the results from a pool.
212 * @param p Pool to allocate from.
213 * @param src The original buffer.
214 * @param slen The length of the original buffer.
215 * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 64 Encoding. If
216 * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_URL,
217 * use RFC4648 Base 64 Encoding with URL and Filename Safe Alphabet.
218 * If APR_ENCODE_BASE64URL, use RFC7515 base64url Encoding.
219 * @param len If not NULL, outputs the length of the encoding (excluding the
220 * trailing NUL).
221 * @return A NUL terminated string allocated from the pool on success,
222 * or NULL if src is NULL or allocation failed or the encoding is not
223 * possible (see apr_encode_base64_binary errors).
224 */
225APR_DECLARE(const char *)apr_pencode_base64_binary(apr_pool_t * p, const unsigned char *src,
226 apr_ssize_t slen, int flags, apr_size_t * len)__attribute__((nonnull(1)));
227
228/**
229 * Convert base64 or base64url with or without padding to text data.
230 * @param dest The destination string, can be NULL to output in \c len the
231 * needed buffer length for decoding.
232 * @param src The base64 string, can be NULL if \c dest is NULL and \c slen
233 * is positive or nul.
234 * @param slen The length of the base64 string, or APR_ENCODE_STRING if
235 * the actual length should be computed based on NUL termination.
236 * @param flags If APR_ENCODE_NONE, attempt to decode the full base64 string,
237 * and return NULL if any bad character is detected. If APR_ENCODE_RELAXED,
238 * decode until the first non base64/base64url character.
239 * @param len If not NULL, outputs the length of the buffer needed for decoding
240 * (including the trailing NUL) if \c dest is NULL, or the actual length of
241 * the decoding (excluding the trailing NUL) if \c dest is not NULL.
242 * @return APR_SUCCESS, or APR_EINVAL if \c slen is not APR_ENCODE_STRING and
243 * negative, or APR_NOTFOUND if \c dest is not NULL and \c src is NULL, or
244 * APR_ENOSPC if \c dest is NULL and the source length (based on \c slen or
245 * APR_ENCODE_STRING) is too big to decode, or APR_EINCOMPLETE if the source
246 * length (based on \c slen or APR_ENCODE_STRING) is invalid for a base64
247 * encoding, or APR_BADCH if a non base64 character is present and
248 * APR_ENCODE_RELAXED is not specified.
249 */
250APR_DECLARE(apr_status_t) apr_decode_base64(char *dest, const char *src,
251 apr_ssize_t slen, int flags, apr_size_t * len);
252
253/**
254 * Convert base64 or base64url with or without padding to binary data.
255 * @param dest The destination string, can be NULL to output in \c len the
256 * needed buffer length for decoding.
257 * @param src The base64 string, can be NULL if \c dest is NULL and \c slen
258 * is positive or nul.
259 * @param slen The length of the base64 string, or APR_ENCODE_STRING if
260 * the actual length should be computed based on NUL termination.
261 * @param flags If APR_ENCODE_NONE, attempt to decode the full base64 string,
262 * and return NULL if any bad character is detected. If APR_ENCODE_RELAXED,
263 * decode until the first non base64/base64url character.
264 * @param len If not NULL, outputs the length of the buffer needed for decoding
265 * (including the trailing NUL) if \c dest is NULL, or the actual length of
266 * the decoding (excluding the trailing NUL) if \c dest is not NULL.
267 * @return APR_SUCCESS, or APR_EINVAL if \c slen is not APR_ENCODE_STRING and
268 * negative, or APR_NOTFOUND if \c dest is not NULL and \c src is NULL, or
269 * APR_ENOSPC if \c dest is NULL and the source length (based on \c slen or
270 * APR_ENCODE_STRING) is too big to decode, or APR_EINCOMPLETE if the source
271 * length (based on \c slen or APR_ENCODE_STRING) is invalid for a base64
272 * encoding, or APR_BADCH if a non base64 character is present and
273 * APR_ENCODE_RELAXED is not specified.
274 */
276 const char *src, apr_ssize_t slen, int flags, apr_size_t * len);
277
278/**
279 * Convert base64 or base64url with or without padding to text data, and
280 * return the results from a pool.
281 * @param p Pool to allocate from.
282 * @param src The base64 string to decode.
283 * @param slen The length of the original string, or APR_ENCODE_STRING if
284 * the actual length should be computed based on NUL termination.
285 * @param flags If APR_ENCODE_NONE, attempt to decode the full original buffer,
286 * and return NULL if any bad character is detected. If APR_ENCODE_RELAXED,
287 * decode until the first non base64/base64url character.
288 * @param len If not NULL, outputs the length of the decoding (excluding the
289 * trailing NUL).
290 * @return A NUL terminated string allocated from the pool on success,
291 * or NULL if src is NULL or allocation failed or the decoding is not
292 * possible (see apr_decode_base64_binary errors).
293 */
294APR_DECLARE(const char *)apr_pdecode_base64(apr_pool_t * p, const char *src,
295 apr_ssize_t slen, int flags, apr_size_t * len)
296 __attribute__((nonnull(1)));
297
298/**
299 * Convert base64 or base64url with or without padding to binary data, and
300 * return the results from a pool.
301 * @param p Pool to allocate from.
302 * @param src The base64 string to decode.
303 * @param slen The length of the original string, or APR_ENCODE_STRING if
304 * the actual length should be computed based on NUL termination.
305 * @param flags If APR_ENCODE_NONE, attempt to decode the full original buffer,
306 * and return NULL if any bad character is detected. If APR_ENCODE_RELAXED,
307 * decode until the first non base64/base64url character.
308 * @param len If not NULL, outputs the length of the decoding (excluding the
309 * trailing NUL).
310 * @return A NUL terminated string allocated from the pool on success,
311 * or NULL if src is NULL or allocation failed or the decoding is not
312 * possible (see apr_decode_base64_binary errors).
313 */
315 const char *src, apr_ssize_t slen, int flags, apr_size_t * len)
316 __attribute__((nonnull(1)));
317
318/**
319 * Convert text data to base32.
320 * @param dest The destination string, can be NULL to output in \c len the
321 * needed buffer length for encoding.
322 * @param src The original string, can be NULL if \c dest is NULL and \c slen
323 * is positive or nul.
324 * @param slen The length of the original string, or APR_ENCODE_STRING if
325 * the actual length should be computed based on NUL termination.
326 * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 32 Encoding. If
327 * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_BASE32HEX,
328 * use RFC4648 base32hex Encoding.
329 * @param len If not NULL, outputs the length of the buffer needed for encoding
330 * (including the trailing NUL) if \c dest is NULL, or the actual length of
331 * the encoding (excluding the trailing NUL) if \c dest is not NULL.
332 * @return APR_SUCCESS, or APR_EINVAL if \c slen is not APR_ENCODE_STRING and
333 * negative, or APR_NOTFOUND if \c dest is not NULL and \c src is NULL, or
334 * APR_ENOSPC if \c dest is NULL and the source length (based on \c slen or
335 * APR_ENCODE_STRING) is too big to encode.
336 */
337APR_DECLARE(apr_status_t) apr_encode_base32(char *dest, const char *src,
338 apr_ssize_t slen, int flags, apr_size_t * len);
339
340/**
341 * Convert binary data to base32.
342 * @param dest The destination string, can be NULL to output in \c len the
343 * needed buffer length for encoding.
344 * @param src The original buffer, can be NULL if \c dest is NULL.
345 * @param slen The length of the original buffer.
346 * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 32 Encoding. If
347 * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_BASE32HEX,
348 * use RFC4648 base32hex Encoding.
349 * @param len If not NULL, outputs the length of the buffer needed for encoding
350 * (including the trailing NUL) if \c dest is NULL, or the actual length of
351 * the encoding (excluding the trailing NUL) if \c dest is not NULL.
352 * @return APR_SUCCESS, or APR_EINVAL if \c slen is negative, or APR_NOTFOUND
353 * if \c dest is not NULL and \c src is NULL, or APR_ENOSPC if \c dest is NULL
354 * and the source length (based on \c slen or APR_ENCODE_STRING) is too big to
355 * encode.
356 */
357APR_DECLARE(apr_status_t) apr_encode_base32_binary(char *dest, const unsigned char *src,
358 apr_ssize_t slen, int flags, apr_size_t * len);
359
360/**
361 * Convert text data to base32, and return the results from a pool.
362 * @param p Pool to allocate from.
363 * @param src The original string.
364 * @param slen The length of the original string, or APR_ENCODE_STRING if
365 * the actual length should be computed based on NUL termination.
366 * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 32 Encoding. If
367 * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_BASE32HEX,
368 * use RFC4648 base32hex Encoding.
369 * @param len If not NULL, outputs the length of the encoding (excluding the
370 * trailing NUL).
371 * @return A NUL terminated string allocated from the pool on success,
372 * or NULL if src is NULL or allocation failed or the encoding is not
373 * possible (see apr_encode_base32 errors).
374 */
375APR_DECLARE(const char *)apr_pencode_base32(apr_pool_t * p, const char *src,
376 apr_ssize_t slen, int flags, apr_size_t * len)
377 __attribute__((nonnull(1)));
378
379/**
380 * Convert binary data to base32, and return the results from a pool.
381 * @param p Pool to allocate from.
382 * @param src The original buffer.
383 * @param slen The length of the original buffer.
384 * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 32 Encoding. If
385 * APR_ENCODE_NOPADDING, omit the = padding character. If APR_ENCODE_BASE32HEX,
386 * use RFC4648 base32hex Encoding.
387 * @param len If not NULL, outputs the length of the encoding (excluding the
388 * trailing NUL).
389 * @return A NUL terminated string allocated from the pool on success,
390 * or NULL if src is NULL or allocation failed or the encoding is not
391 * possible (see apr_encode_base32_binary errors).
392 */
393APR_DECLARE(const char *)apr_pencode_base32_binary(apr_pool_t * p, const unsigned char *src,
394 apr_ssize_t slen, int flags, apr_size_t * len)
395 __attribute__((nonnull(1)));
396
397/**
398 * Convert base32 or base32hex with or without padding to text data.
399 * @param dest The destination string, can be NULL to output in \c len the
400 * needed buffer length for decoding.
401 * @param src The base32 string, can be NULL if \c dest is NULL and \c slen
402 * is positive or nul.
403 * @param slen The length of the base32 string, or APR_ENCODE_STRING if
404 * the actual length should be computed based on NUL termination.
405 * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 32 Encoding. If
406 * APR_ENCODE_BASE32HEX, use RFC4648 base32hex Encoding.
407 * @param len If not NULL, outputs the length of the buffer needed for decoding
408 * (including the trailing NUL) if \c dest is NULL, or the actual length of
409 * the decoding (excluding the trailing NUL) if \c dest is not NULL.
410 * @return APR_SUCCESS, or APR_EINVAL if \c slen is not APR_ENCODE_STRING and
411 * negative, or APR_NOTFOUND if \c dest is not NULL and \c src is NULL, or
412 * APR_ENOSPC if \c dest is NULL and the source length (based on \c slen or
413 * APR_ENCODE_STRING) is too big to decode, or APR_EINCOMPLETE if the source
414 * length (based on \c slen or APR_ENCODE_STRING) is invalid for a base32
415 * encoding, or APR_BADCH if a non base32 character is present and
416 * APR_ENCODE_RELAXED is not specified.
417 */
418APR_DECLARE(apr_status_t) apr_decode_base32(char *dest, const char *src,
419 apr_ssize_t slen, int flags, apr_size_t * len);
420
421/**
422 * Convert base32 or base32hex with or without padding to binary data.
423 * @param dest The destination string, can be NULL to output in \c len the
424 * needed buffer length for decoding.
425 * @param src The base32 string, can be NULL if \c dest is NULL and \c slen
426 * is positive or nul.
427 * @param slen The length of the base32 string, or APR_ENCODE_STRING if
428 * the actual length should be computed based on NUL termination.
429 * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 32 Encoding. If
430 * APR_ENCODE_BASE32HEX, use RFC4648 base32hex Encoding.
431 * @param len If not NULL, outputs the length of the buffer needed for decoding
432 * (including the trailing NUL) if \c dest is NULL, or the actual length of
433 * the decoding (excluding the trailing NUL) if \c dest is not NULL.
434 * @return APR_SUCCESS, or APR_EINVAL if \c slen is not APR_ENCODE_STRING and
435 * negative, or APR_NOTFOUND if \c dest is not NULL and \c src is NULL, or
436 * APR_ENOSPC if \c dest is NULL and the source length (based on \c slen or
437 * APR_ENCODE_STRING) is too big to decode, or APR_EINCOMPLETE if the source
438 * length (based on \c slen or APR_ENCODE_STRING) is invalid for a base32
439 * encoding, or APR_BADCH if a non base32 character is present and
440 * APR_ENCODE_RELAXED is not specified.
441 */
443 const char *src, apr_ssize_t slen, int flags, apr_size_t * len);
444
445/**
446 * Convert base32 or base32hex with or without padding to text data, and
447 * return the results from a pool.
448 * @param p Pool to allocate from.
449 * @param src The base32 string to decode.
450 * @param slen The length of the original string, or APR_ENCODE_STRING if
451 * the actual length should be computed based on NUL termination.
452 * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 32 Encoding. If
453 * APR_ENCODE_BASE32HEX, use RFC4648 base32hex Encoding.
454 * @param len If not NULL, outputs the length of the encoding (excluding the
455 * trailing NUL).
456 * @return A NUL terminated string allocated from the pool on success,
457 * or NULL if src is NULL or allocation failed or the decoding is not
458 * possible (see apr_decode_base32 errors).
459 */
460APR_DECLARE(const char *)apr_pdecode_base32(apr_pool_t * p, const char *src,
461 apr_ssize_t slen, int flags, apr_size_t * len)
462 __attribute__((nonnull(1)));
463
464/**
465 * Convert base32 or base32hex with or without padding to binary data, and
466 * return the results from a pool.
467 * @param p Pool to allocate from.
468 * @param src The base32 string to decode.
469 * @param slen The length of the original string, or APR_ENCODE_STRING if
470 * the actual length should be computed based on NUL termination.
471 * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 32 Encoding. If
472 * APR_ENCODE_BASE32HEX, use RFC4648 base32hex Encoding.
473 * @param len If not NULL, outputs the length of the encoding (excluding the
474 * trailing NUL).
475 * @return A NUL terminated string allocated from the pool on success,
476 * or NULL if src is NULL or allocation failed or the decoding is not
477 * possible (see apr_decode_base32_binary errors).
478 */
480 const char *src, apr_ssize_t slen, int flags, apr_size_t * len)
481 __attribute__((nonnull(1)));
482
483/**
484 * Convert text data to base16 (hex).
485 * @param dest The destination string, can be NULL to output in \c len the
486 * needed buffer length for encoding.
487 * @param src The original string, can be NULL if \c dest is NULL and \c slen
488 * is positive or nul.
489 * @param slen The length of the original string, or APR_ENCODE_STRING if
490 * the actual length should be computed based on NUL termination.
491 * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 16 Encoding. If
492 * APR_ENCODE_COLON, separate each token with a colon.
493 * @param len If not NULL, outputs the length of the buffer needed for encoding
494 * (including the trailing NUL) if \c dest is NULL, or the actual length of
495 * the encoding (excluding the trailing NUL) if \c dest is not NULL.
496 * @return APR_SUCCESS, or APR_EINVAL if \c slen is not APR_ENCODE_STRING and
497 * negative, or APR_NOTFOUND if \c dest is not NULL and \c src is NULL, or
498 * APR_ENOSPC if \c dest is NULL and the source length (based on \c slen or
499 * APR_ENCODE_STRING) is too big to encode.
500 */
501APR_DECLARE(apr_status_t) apr_encode_base16(char *dest, const char *src,
502 apr_ssize_t slen, int flags, apr_size_t * len);
503
504/**
505 * Convert binary data to base16 (hex).
506 * @param dest The destination string, can be NULL to output in \c len the
507 * needed buffer length for encoding.
508 * @param src The original buffer, can be NULL if \c dest is NULL.
509 * @param slen The length of the original buffer.
510 * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 16 Encoding. If
511 * APR_ENCODE_COLON, separate each token with a colon.
512 * @param len If not NULL, outputs the length of the buffer needed for encoding
513 * (including the trailing NUL) if \c dest is NULL, or the actual length of
514 * the encoding (excluding the trailing NUL) if \c dest is not NULL.
515 * @return APR_SUCCESS, or APR_EINVAL if \c slen is negative, or APR_NOTFOUND
516 * if \c dest is not NULL and \c src is NULL, or APR_ENOSPC if \c dest is NULL
517 * and the source length (based on \c slen or APR_ENCODE_STRING) is too big to
518 * encode.
519 */
521 const unsigned char *src, apr_ssize_t slen, int flags,
522 apr_size_t * len);
523
524/**
525 * Convert text data to base16 (hex), and return the results from a
526 * pool.
527 * @param p Pool to allocate from.
528 * @param src The original string.
529 * @param slen The length of the original string, or APR_ENCODE_STRING if
530 * the actual length should be computed based on NUL termination.
531 * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 16 Encoding. If
532 * APR_ENCODE_COLON, separate each token with a colon.
533 * @param len If not NULL, outputs the length of the encoding (excluding the
534 * trailing NUL).
535 * @return A NUL terminated string allocated from the pool on success,
536 * or NULL if src is NULL or allocation failed or the encoding is not
537 * possible (see apr_encode_base16 errors).
538 */
539APR_DECLARE(const char *)apr_pencode_base16(apr_pool_t * p, const char *src,
540 apr_ssize_t slen, int flags, apr_size_t * len)
541 __attribute__((nonnull(1)));
542
543/**
544 * Convert binary data to base16 (hex), and return the results from a
545 * pool.
546 * @param p Pool to allocate from.
547 * @param src The original buffer.
548 * @param slen The length of the original buffer.
549 * @param flags If APR_ENCODE_NONE, emit RFC4648 Base 16 Encoding. If
550 * APR_ENCODE_COLON, separate each token with a colon.
551 * @param len If not NULL, outputs the length of the encoding (excluding the
552 * trailing NUL).
553 * @return A NUL terminated string allocated from the pool on success,
554 * or NULL if src is NULL or allocation failed or the encoding is not
555 * possible (see apr_encode_base16_binary errors).
556 */
558 const unsigned char *src, apr_ssize_t slen,
559 int flags, apr_size_t * len)__attribute__((nonnull(1)));
560
561/**
562 * Convert base16 (hex) to text data.
563 * @param dest The destination string, can be NULL to output in \c len the
564 * needed buffer length for decoding.
565 * @param src The base16 string, can be NULL if \c dest is NULL and \c slen
566 * is positive or nul.
567 * @param slen The length of the base16 string, or APR_ENCODE_STRING if
568 * the actual length should be computed based on NUL termination.
569 * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 16 Encoding. If
570 * APR_ENCODE_COLON, allow tokens to be separated with a colon.
571 * @param len If not NULL, outputs the length of the buffer needed for decoding
572 * (including the trailing NUL) if \c dest is NULL, or the actual length of
573 * the decoding (excluding the trailing NUL) if \c dest is not NULL.
574 * @return APR_SUCCESS, or APR_EINVAL if \c slen is not APR_ENCODE_STRING and
575 * negative, or APR_NOTFOUND if \c dest is not NULL and \c src is NULL, or
576 * APR_ENOSPC if \c dest is NULL and the source length (based on \c slen or
577 * APR_ENCODE_STRING) is too big to decode, or APR_EINCOMPLETE if the source
578 * length (based on \c slen or APR_ENCODE_STRING) is invalid for a base16
579 * encoding, or APR_BADCH if a non base16 character is present and
580 * APR_ENCODE_RELAXED is not specified.
581 */
582APR_DECLARE(apr_status_t) apr_decode_base16(char *dest, const char *src,
583 apr_ssize_t slen, int flags, apr_size_t * len);
584
585/**
586 * Convert base16 (hex) to binary data.
587 * @param dest The destination string, can be NULL to output in \c len the
588 * needed buffer length for decoding.
589 * @param src The base16 string, can be NULL if \c dest is NULL and \c slen
590 * is positive or nul.
591 * @param slen The length of the base16 string, or APR_ENCODE_STRING if
592 * the actual length should be computed based on NUL termination.
593 * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 16 Encoding. If
594 * APR_ENCODE_COLON, allow tokens to be separated with a colon.
595 * @param len If not NULL, outputs the length of the buffer needed for decoding
596 * (including the trailing NUL) if \c dest is NULL, or the actual length of
597 * the decoding (excluding the trailing NUL) if \c dest is not NULL.
598 * @return APR_SUCCESS, or APR_EINVAL if \c slen is not APR_ENCODE_STRING and
599 * negative, or APR_NOTFOUND if \c dest is not NULL and \c src is NULL, or
600 * APR_ENOSPC if \c dest is NULL and the source length (based on \c slen or
601 * APR_ENCODE_STRING) is too big to decode, or APR_EINCOMPLETE if the source
602 * length (based on \c slen or APR_ENCODE_STRING) is invalid for a base16
603 * encoding, or APR_BADCH if a non base16 character is present and
604 * APR_ENCODE_RELAXED is not specified.
605 */
607 const char *src, apr_ssize_t slen, int flags, apr_size_t * len);
608
609/**
610 * Convert base16 (hex) and return the results from a pool.
611 * @param p Pool to allocate from.
612 * @param src The base16 string to decode.
613 * @param slen The length of the original string, or APR_ENCODE_STRING if
614 * the actual length should be computed based on NUL termination.
615 * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 16 Encoding. If
616 * APR_ENCODE_COLON, allow tokens to be separated with a colon.
617 * @param len If not NULL, outputs the length of the encoding (excluding the
618 * trailing NUL).
619 * @return A NUL terminated string allocated from the pool on success,
620 * or NULL if src is NULL or allocation failed or the decoding is not
621 * possible (see apr_decode_base16 errors).
622 */
623APR_DECLARE(const char *)apr_pdecode_base16(apr_pool_t * p, const char *src,
624 apr_ssize_t slen, int flags, apr_size_t * len)
625 __attribute__((nonnull(1)));
626
627/**
628 * Convert base16 (hex) to binary data, and return the results from a pool.
629 * @param p Pool to allocate from.
630 * @param src The base16 string to decode.
631 * @param slen The length of the original string, or APR_ENCODE_STRING if
632 * the actual length should be computed based on NUL termination.
633 * @param flags If APR_ENCODE_NONE, parse RFC4648 Base 16 Encoding. If
634 * APR_ENCODE_COLON, allow tokens to be separated with a colon.
635 * @param len If not NULL, outputs the length of the encoding (excluding the
636 * trailing NUL).
637 * @return A NUL terminated string allocated from the pool on success,
638 * or NULL if src is NULL or allocation failed or the decoding is not
639 * possible (see apr_decode_base16_binary errors).
640 */
642 const char *src, apr_ssize_t slen, int flags, apr_size_t * len)
643 __attribute__((nonnull(1)));
644
645/** @} */
646#ifdef __cplusplus
647}
648#endif
649
650#endif /* !APR_ENCODE_H */
APR Platform Definitions.
APR Miscellaneous library routines.
apr_status_t apr_decode_base16(char *dest, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
const char * apr_pdecode_base16(apr_pool_t *p, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
apr_status_t apr_encode_base64(char *dest, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
const char * apr_pencode_base32(apr_pool_t *p, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
const char * apr_pencode_base64(apr_pool_t *p, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
apr_status_t apr_encode_base32_binary(char *dest, const unsigned char *src, apr_ssize_t slen, int flags, apr_size_t *len)
const unsigned char * apr_pdecode_base16_binary(apr_pool_t *p, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
apr_status_t apr_decode_base16_binary(unsigned char *dest, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
const char * apr_pdecode_base32(apr_pool_t *p, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
const unsigned char * apr_pdecode_base32_binary(apr_pool_t *p, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
const char * apr_pdecode_base64(apr_pool_t *p, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
apr_status_t apr_encode_base16_binary(char *dest, const unsigned char *src, apr_ssize_t slen, int flags, apr_size_t *len)
apr_status_t apr_decode_base64_binary(unsigned char *dest, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
apr_status_t apr_decode_base64(char *dest, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
const unsigned char * apr_pdecode_base64_binary(apr_pool_t *p, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
const char * apr_pencode_base16(apr_pool_t *p, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
apr_status_t apr_decode_base32_binary(unsigned char *dest, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
apr_status_t apr_decode_base32(char *dest, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
const char * apr_pencode_base16_binary(apr_pool_t *p, const unsigned char *src, apr_ssize_t slen, int flags, apr_size_t *len)
const char * apr_pencode_base64_binary(apr_pool_t *p, const unsigned char *src, apr_ssize_t slen, int flags, apr_size_t *len)
const char * apr_pencode_base32_binary(apr_pool_t *p, const unsigned char *src, apr_ssize_t slen, int flags, apr_size_t *len)
apr_status_t apr_encode_base64_binary(char *dest, const unsigned char *src, apr_ssize_t slen, int flags, apr_size_t *len)
apr_status_t apr_encode_base16(char *dest, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
apr_status_t apr_encode_base32(char *dest, const char *src, apr_ssize_t slen, int flags, apr_size_t *len)
int apr_status_t
Definition apr_errno.h:44
#define APR_DECLARE(type)
Definition apr.h:498
struct apr_pool_t apr_pool_t
Definition apr_pools.h:60