Macros | Functions
base64.h File Reference

BASE64 encoding and decoding. More...

Macros

#define VTM_BASE64_ENC_BUF_LEN(INPUT_LEN)   (4 * (((INPUT_LEN) + 2) / 3) + 1)
 
#define VTM_BASE64_DEC_BUF_LEN(INPUT_LEN)   (((INPUT_LEN) / 4) * 3)
 

Functions

VTM_API int vtm_base64_encode (const void *input, size_t len, void *buf, size_t buf_len)
 
VTM_API int vtm_base64_decode (const void *input, size_t len, void *buf, size_t *buf_len)
 

Macro Definition Documentation

#define VTM_BASE64_ENC_BUF_LEN (   INPUT_LEN)    (4 * (((INPUT_LEN) + 2) / 3) + 1)

Calculates the necessary buffer size for encoding.

Parameters
INPUT_LENthe input length
#define VTM_BASE64_DEC_BUF_LEN (   INPUT_LEN)    (((INPUT_LEN) / 4) * 3)

Calculates the necessary buffer size for decoding.

Parameters
INPUT_LENlength of BASE64 string

Function Documentation

VTM_API int vtm_base64_encode ( const void *  input,
size_t  len,
void *  buf,
size_t  buf_len 
)

Encodes a memory chunk into BASE64 format.

The output is written including a final NUL-terminator.

Parameters
inputpointer to input memory
lensize of input
bufpreallocated buffer where BASE64 string will be written to
buf_lensize of buffer
Returns
VTM_OK if encoding was successful
VTM_E_INVALID_ARG if one of the supplied arguments is invalid, for example a too small buffer
VTM_API int vtm_base64_decode ( const void *  input,
size_t  len,
void *  buf,
size_t *  buf_len 
)

Decodes a BASE64 string.

Parameters
inputpointer to begin of BASE64 string
lenlength of input string
bufpreallocated buffer where decoded data will be written to
[in,out]buf_lensize of buffer, overwritten with used buffer size
Returns
VTM_OK if decoding was successful
VTM_E_INVALID_ARG if one of the supplied arguments is invalid, for example a too small buffer