JabberWerxC  2015.1.1
Functions
base64.h File Reference

Functions for encoding to and decoding from Base 64. More...

#include <sys/types.h>
#include "../basics.h"

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)
 

Detailed Description

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.

Function Documentation

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.
Invariant
result != NULL
orig != NULL
result_len != NULL
Parameters
[in]origThe array containing the base 64 data to decode.
[in]orig_lenThe number of bytes to decode from orig or -1 to calculate.
[out]resultThe output byte array where the decoded data is stored.
[out]result_lenThe size of the new allocated result byte array.
[out]errThe error information (provide NULL to ignore)
Return values
booltrue 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.
Invariant
result != NULL
orig != NULL
Parameters
[in]origThe array containing the bytes to encode.
[in]orig_lenThe number of bytes to encode from orig
[out]resultThe output byte array where the encoded data is stored.
[out]result_lenIf non-NULL, the size of the new allocated result byte array.
[out]errThe error information (provide NULL to ignore)
Return values
booltrue if encoding was successful, false otherwise.