chttp · Section 3
chttp_base64_decode_mp
NAME
chttp_base64_decode_mp - decode a base64 string with a custom allocator
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/chttp.h>
void *chttp_base64_decode_mp(ccol_memmgmt_procs *mp,
const char *b64_input, size_t *out_len);
DESCRIPTION
This function decodes a NUL-terminated string of standard RFC 4648 base64, with the '+' and '/' alphabet and '=' padding. It takes the input length from strlen(b64_input), and that length must be a multiple of 4 bytes. Any '=' padding must be the last character or the last two characters. In a padded final group, the bits that no decoded byte uses must be zero (RFC 4648 section 3.5), so every byte string has exactly one encoding: "QQ==" decodes to "A" while "QR==" is malformed. Any malformed input is rejected, whether it has an invalid character, padding in the wrong place, nonzero padding bits or the wrong length. The returned buffer ends with a NUL, which is handy when you decode text. The decoded data can hold NUL bytes of its own though, so always take the real size from out_len and never from strlen().
PARAMETERS
mp A custom allocator, or NULL for malloc/free.
b64_input The NUL-terminated base64 string to decode. It must not
be NULL.
out_len Optional. It receives the number of decoded bytes. Pass
NULL if you don't need it.
RETURN VALUE
A new buffer with the decoded bytes on success. NULL if the allocation fails or the input is malformed.
SEE ALSO
chttp_base64_decode(3), chttp_base64_encode_mp(3), chttp_basic_auth_mp(3)