Base64 module implementation file. More...
#include "base64.h"
#include "mcl_core/mcl_assert.h"
#include "mcl_core/mcl_memory.h"
#include "mcl_core/mcl_string_util.h"
Go to the source code of this file.
Macros | |
#define | PADDING_CHAR '=' |
#define | QUANTUM_SIZE 4 |
#define | INPUT_GROUP_SIZE 3 |
#define | MAX_PADDING_CHAR_COUNT 2 |
#define | BASE64_BIT_COUNT_PER_CHARACTER 6 |
#define | MASK_FOR_ENCODING 0x3FU |
#define | MASK_FOR_LOW_BYTE 0xFFU |
#define | BYTE_BIT_COUNT 8 |
Functions | |
static mcl_error_t | _encode_with_table (const char *table, const mcl_uint8_t *data, mcl_size_t data_size, char **encoded_data) |
static mcl_error_t | _decode_with_table (const mcl_uint8_t *table, const char *encoded_data, mcl_uint8_t **decoded_data, mcl_size_t *decoded_data_size) |
static mcl_error_t | _decode_quantum (const mcl_uint8_t *table, const char *source, mcl_uint8_t *destination) |
mcl_error_t | base64_decode (const char *encoded_data, mcl_uint8_t **decoded_data, mcl_size_t *decoded_data_size) |
mcl_error_t | base64_url_decode (const char *encoded_data, mcl_uint8_t **decoded_data, mcl_size_t *decoded_data_size) |
mcl_error_t | base64_encode (const mcl_uint8_t *data, mcl_size_t data_size, char **encoded_data) |
mcl_error_t | base64_url_encode (const mcl_uint8_t *data, mcl_size_t data_size, char **encoded_data) |
Variables | |
static const char | base64_encode_table [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" |
static const mcl_uint8_t | base64_decode_table [] |
static const char | base64_url_encode_table [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" |
static const mcl_uint8_t | base64_url_decode_table [] |
Base64 module implementation file.
Definition in file base64.c.
#define BASE64_BIT_COUNT_PER_CHARACTER 6 |
Definition at line 23 of file base64.c.
Referenced by _decode_quantum(), and _encode_with_table().
#define BYTE_BIT_COUNT 8 |
Definition at line 30 of file base64.c.
Referenced by _decode_quantum(), and _encode_with_table().
#define INPUT_GROUP_SIZE 3 |
Definition at line 19 of file base64.c.
Referenced by _decode_quantum(), _decode_with_table(), and _encode_with_table().
#define MASK_FOR_ENCODING 0x3FU |
Definition at line 26 of file base64.c.
Referenced by _encode_with_table().
#define MASK_FOR_LOW_BYTE 0xFFU |
Definition at line 29 of file base64.c.
Referenced by _decode_quantum().
#define MAX_PADDING_CHAR_COUNT 2 |
Definition at line 22 of file base64.c.
Referenced by _decode_quantum(), and _decode_with_table().
#define PADDING_CHAR '=' |
Definition at line 15 of file base64.c.
Referenced by _decode_quantum(), _decode_with_table(), and _encode_with_table().
#define QUANTUM_SIZE 4 |
Definition at line 18 of file base64.c.
Referenced by _decode_quantum(), _decode_with_table(), and _encode_with_table().
|
static |
Definition at line 242 of file base64.c.
References BASE64_BIT_COUNT_PER_CHARACTER, BYTE_BIT_COUNT, INPUT_GROUP_SIZE, MASK_FOR_LOW_BYTE, MAX_PADDING_CHAR_COUNT, MCL_BAD_CONTENT_ENCODING, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_OK, MCL_VERBOSE, PADDING_CHAR, and QUANTUM_SIZE.
Referenced by _decode_with_table().
|
static |
Definition at line 143 of file base64.c.
References _decode_quantum(), INPUT_GROUP_SIZE, MAX_PADDING_CHAR_COUNT, MCL_ASSERT_CODE_MESSAGE, MCL_BAD_CONTENT_ENCODING, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, MCL_MALLOC, MCL_NULL, MCL_NULL_CHAR, MCL_NULL_CHAR_SIZE, MCL_OK, MCL_OUT_OF_MEMORY, mcl_string_util_strlen(), MCL_VERBOSE, PADDING_CHAR, and QUANTUM_SIZE.
Referenced by base64_decode(), and base64_url_decode().
|
static |
Definition at line 301 of file base64.c.
References BASE64_BIT_COUNT_PER_CHARACTER, BYTE_BIT_COUNT, INPUT_GROUP_SIZE, MASK_FOR_ENCODING, MCL_ASSERT_CODE_MESSAGE, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_MALLOC, MCL_NULL, MCL_NULL_CHAR, MCL_NULL_CHAR_SIZE, MCL_OK, MCL_OUT_OF_MEMORY, PADDING_CHAR, and QUANTUM_SIZE.
Referenced by base64_encode(), and base64_url_encode().
mcl_error_t base64_decode | ( | const char * | encoded_data, |
mcl_uint8_t ** | decoded_data, | ||
mcl_size_t * | decoded_data_size | ||
) |
This function is used for decoding a base64 encoded, zero-terminated string in encoded_data
and return decoded data in decoded_data
with size decoded_data_size
.
When decoded data length is 0, returns MCL_NULL in decoded_data
.
encoded_data | [in] Zero-terminated string which is base64 encoded and has to be decoded. |
decoded_data | [out] Newly allocated memory holding decoded data. |
decoded_data_size | [out] Size of decoded data. |
encoded_data
has invalid length (0 or not multiples of 4) or is invalidly encoded. Definition at line 93 of file base64.c.
References _decode_with_table(), base64_decode_table, MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.
Referenced by security_handler_base64_decode().
mcl_error_t base64_encode | ( | const mcl_uint8_t * | data, |
mcl_size_t | data_size, | ||
char ** | encoded_data | ||
) |
This function is used for base64 encoding of data in data
and return encoded data in encoded_data
.
When encoded data length is 0, returns MCL_NULL in encoded_data
.
data | [in] Input data that has to be base64 encoded. |
data_size | [in] Size of given input data . |
encoded_data | [out] Newly allocated string holding encoded data. |
Definition at line 119 of file base64.c.
References _encode_with_table(), base64_encode_table, MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.
Referenced by security_handler_base64_encode().
mcl_error_t base64_url_decode | ( | const char * | encoded_data, |
mcl_uint8_t ** | decoded_data, | ||
mcl_size_t * | decoded_data_size | ||
) |
This function is used for decoding a base64 URL encoded, zero-terminated string in encoded_data
and return decoded data in decoded_data
with size decoded_data_size
.
When decoded data length is 0, returns MCL_NULL in decoded_data
.
encoded_data | [in] Zero-terminated string which is base64 URL encoded and has to be decoded. |
decoded_data | [out] Newly allocated memory holding decoded data. |
decoded_data_size | [out] Size of decoded_data . |
encoded_data
has invalid length (0 or not multiples of 4) or is invalidly encoded. Definition at line 106 of file base64.c.
References _decode_with_table(), base64_url_decode_table, MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.
mcl_error_t base64_url_encode | ( | const mcl_uint8_t * | data, |
mcl_size_t | data_size, | ||
char ** | encoded_data | ||
) |
This function is used for base64 URL encoding of data in data
and return encoded data in encoded_data
.
When encoded data length is 0, returns MCL_NULL in encoded_data
.
data | [in] Input data that has to be base64 URL encoded. |
data_size | [in] Size of given input data . |
encoded_data | [out] Newly allocated string holding encoded data. |
Definition at line 131 of file base64.c.
References _encode_with_table(), base64_url_encode_table, MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.
Referenced by _base64_encode_big_number(), and security_handler_base64_url_encode().
|
static |
Definition at line 37 of file base64.c.
Referenced by base64_decode().
|
static |
Definition at line 33 of file base64.c.
Referenced by base64_encode().
|
static |
Definition at line 63 of file base64.c.
Referenced by base64_url_decode().
|
static |
Definition at line 59 of file base64.c.
Referenced by base64_url_encode().