JabberWerxC
2015.1.1
|
Functions for encoding to and decoding from Base 64. More...
Go to the source code of this file.
Functions | |
JABBERWERX_API bool | jw_base64_encode (const uint8_t *orig, size_t orig_len, char **result, size_t *result_len, jw_err *err) |
JABBERWERX_API bool | jw_base64_decode (const char *orig, ssize_t orig_len, uint8_t **result, size_t *result_len, jw_err *err) |
Functions for encoding to and decoding from Base 64.
Copyrights
Portions created or assigned to Cisco Systems, Inc. are Copyright (c) 2010-2015 Cisco Systems, Inc. All Rights Reserved. See LICENSE for details.
JABBERWERX_API bool jw_base64_decode | ( | const char * | orig, |
ssize_t | orig_len, | ||
uint8_t ** | result, | ||
size_t * | result_len, | ||
jw_err * | err | ||
) |
Decode base64 encoded byte array (without whitespace) into nonencoded binary stream. If orig_len is -1, this function uses strlen(orig) to determine the size. If orig_len is 0 then result is an "empty string" (*result && **result = 0).
NOTE: This function will allocate the memory needed to store the decoded data. Result MUST be released using jw_data_free.
This function can generate the following errors (set when returning false):
JW_ERR_INVALID_ARG
If orig contains bytes that are not Base 64 encoding, or if orig_len < -1 JW_ERR_NO_MEMORY
If result buffer could not be allocated.[in] | orig | The array containing the base 64 data to decode. |
[in] | orig_len | The number of bytes to decode from orig or -1 to calculate. |
[out] | result | The output byte array where the decoded data is stored. |
[out] | result_len | The size of the new allocated result byte array. |
[out] | err | The error information (provide NULL to ignore) |
bool | true if decoding was successful, or false otherwise |
JABBERWERX_API bool jw_base64_encode | ( | const uint8_t * | orig, |
size_t | orig_len, | ||
char ** | result, | ||
size_t * | result_len, | ||
jw_err * | err | ||
) |
Encode a byte array into a base64 byte array (without whitespace). The result buffer is null-terminated. If orig_len is 0, result is an empty string.
NOTE: This function will allocate the memory needed to store the encoded data. Result MUST be released using jw_data_free.
This function can generate the following errors (set when returning false):
JW_ERR_NO_MEMORY
If result buffer could not be allocated.[in] | orig | The array containing the bytes to encode. |
[in] | orig_len | The number of bytes to encode from orig |
[out] | result | The output byte array where the encoded data is stored. |
[out] | result_len | If non-NULL, the size of the new allocated result byte array. |
[out] | err | The error information (provide NULL to ignore) |
bool | true if encoding was successful, false otherwise. |