C Collections

chttp · Section 3

chttp_base64_encode_mp

chttp_base64_encode_mp - encode a buffer as base64 with a custom allocator

C Collections (libccollections, -lccollections)

#include <ccollections/chttp.h>
 
char *chttp_base64_encode_mp(ccol_memmgmt_procs *mp,
                             const void *data, size_t len,
                             size_t *out_len);

This function encodes len bytes of data as standard RFC 4648 base64,
with the '+' and '/' alphabet and '=' padding.  That is the variant
that RFC 7617 Basic auth needs and the one HTTP uses everywhere.

mp       A custom allocator, or NULL for malloc/free.
data     The buffer to encode. It can be NULL only if len is 0.
len      The number of bytes in data.
out_len  Optional. It receives the length of the returned string,
         without the terminating NUL. Pass NULL if you don't need
         it.

A new NUL-terminated base64 string on success.
NULL if the allocation fails, if data is NULL and len is not zero, or
if len is so large that the encoded size overflows size_t.

chttp_base64_encode(3), chttp_base64_decode_mp(3), chttp_basic_auth_mp(3)