-
Notifications
You must be signed in to change notification settings - Fork 0
DOCS
MTBase64 consists of a set of functions to handle encoded and decoded data in various stored forms.
This is accomplished by defining an alphabet/table object that is used by MTBase64 methods to encode and decode data.
All MTBase64 constants and methods are stored inside MTBase64
namespace.
- MTBase64::kDefaultBase64 Standard Base64 alphabet
- MTBase64::kUrlSafeBase64 URL safe Base64 alphabet
- MTBase64::IndexTable Defines a Base64 alphabet/table object
- MTBase64::IndexTable.Lookup Look ups the encoded byte
- MTBase64::IndexTable.ReverseLookup Look ups the decoded byte
- MTBase64::IndexTable.GetPadding Returns the defined padding value in the table object
- MTBase64::GetPaddingNum Returns number of prefix padding symbols in data
- MTBase64::EncodeCTR Encodes data inside a container
- MTBase64::DecodeCTR Decodes data inside a container
- MTBase64::EncodeMem Encodes data inside memory pointer
- MTBase64::DecodeMem Decodes data inside memory pointer
- MTBase64::ValidPaddedEncodedLength Checks if the encoded data length with padding is valid
- MTBase64::ValidUnpaddedEncodedLength Checks if the encoded data length without padding is valid
- MTBase64::GetEncodedLength Returns encoded length from data size
- MTBase64::GetDecodedLength Returns decoded length from data size
Type
Constant
A table object containing the standard Base64 alphabet/table. As for all table objects, the table object is used in MTBase64 methods to encode and decode data stored in containers and raw C memory.
The alphabet table can be seen below.
ID | CHAR | ID | CHAR | ID | CHAR | ID | CHAR |
---|---|---|---|---|---|---|---|
0 | A | 16 | Q | 32 | g | 48 | w |
1 | B | 17 | R | 33 | h | 49 | x |
2 | C | 18 | S | 34 | i | 50 | y |
3 | D | 19 | T | 35 | j | 51 | z |
4 | E | 20 | U | 36 | k | 52 | 0 |
5 | F | 21 | V | 37 | l | 53 | 1 |
6 | G | 22 | W | 38 | m | 54 | 2 |
7 | H | 23 | X | 39 | n | 55 | 3 |
8 | I | 24 | Y | 40 | o | 56 | 4 |
9 | J | 25 | Z | 41 | p | 57 | 5 |
10 | K | 26 | a | 42 | q | 58 | 6 |
11 | L | 27 | b | 43 | r | 59 | 7 |
12 | M | 28 | c | 44 | s | 60 | 8 |
13 | N | 29 | d | 45 | t | 61 | 9 |
14 | O | 30 | e | 46 | u | 62 | + |
15 | P | 31 | f | 47 | v | 63 | / |
PAD | = |
Type
Constant
A table object containing the Base64 format that is used in the URL.
The alphabet can be seen below.
ID | CHAR | ID | CHAR | ID | CHAR | ID | CHAR |
---|---|---|---|---|---|---|---|
0 | A | 16 | Q | 32 | g | 48 | w |
1 | B | 17 | R | 33 | h | 49 | x |
2 | C | 18 | S | 34 | i | 50 | y |
3 | D | 19 | T | 35 | j | 51 | z |
4 | E | 20 | U | 36 | k | 52 | 0 |
5 | F | 21 | V | 37 | l | 53 | 1 |
6 | G | 22 | W | 38 | m | 54 | 2 |
7 | H | 23 | X | 39 | n | 55 | 3 |
8 | I | 24 | Y | 40 | o | 56 | 4 |
9 | J | 25 | Z | 41 | p | 57 | 5 |
10 | K | 26 | a | 42 | q | 58 | 6 |
11 | L | 27 | b | 43 | r | 59 | 7 |
12 | M | 28 | c | 44 | s | 60 | 8 |
13 | N | 29 | d | 45 | t | 61 | 9 |
14 | O | 30 | e | 46 | u | 62 | - |
15 | P | 31 | f | 47 | v | 63 | _ |
PAD | = (?) |
Type
Function (Constructor)
Args
const std::array<uint8_t, 64>& linear_table
uint8_t padding = 0x3D
Returns
Raises
Constructs an MTBase64::IndexTable
object from a std::array
containing the Base64 table/alphabet; the Base64 alphabet should be encoded as shown here.
The given alphabet needs to be a valid std::array<uint8_t, 64>
, where the nth element represents the nth index value, and where no duplicates occur.
By giving the Base64 alphabet, the constructor generates a reverse look-up alphabet that is used for decoding.
Type
Function
Args
uint8_t index
Returns
uint8_t
Raises
std::out_of_range
Returns the value at the given index from the Base64 alphabet. If the value at the given index can't be found, a std::out_of_range
exception is raised.
Type
Function
Args
uint8_t index
Returns
uint8_t
Raises
std::out_of_range
Returns the value at the given index from the auto-generated reversed Base64 alphabet. If the value at the given index can't be found, an std::out_of_range
exception is raised.
Type
Function
Args
Returns
uint8_t
Raises
Returns the set padding byte in the MTBase64::IndexTable
object.
Type
Function
Args
const C& data
const IndexTable& table
Returns
uint8_t
Raises
std::out_of_range
Returns the number of prefix padding bytes in the given data; the returned number is between 0 and 2. If the size of the given data is less than 2 elements, a std::out_of_range
exception is raised.
Type
Function
Args
const Container<T>& input
const IndexTable& table
bool using_padding = true
Returns
Container<T>
Raises
Encodes the data stored inside the given container using the given Base64 alphabet inside an MTBase64::IndexTable
object; note that the container type <T> needs to be an integer or char. Padded or unpadded Base64 encoding is set using the using_padding
argument.
Type
Function
Args
const Container<T>& input
const IndexTable& table
bool using_padding = true
Returns
Container<T>
Raises
MTBase64::MTBase64Exception::kNotValidBase64
MTBase64::MTBase64Exception::kIllegalFunctionCall
Decodes the data stored inside the given container using the given Base64 alphabet inside an MTBase64::IndexTable
object. As with the MTBase64::EncodeCTR
method, the container type needs to either be char or integer.
When padding is set and no valid padding is found at the end of the given data sequence, an MTBase64::MTBase64Exception::kNotValidBase64
exception is raised.
If corrupted Base64 encoded data is given, MTBase64::MTBase64Exception::kIllegalFunctionCall
is raised.
Type
Function
Args
uint8_t* dest
const uint8_t* src
std::size_t src_len
const IndexTable& table
bool using_padding = true
Returns
Raises
MTBase64::MTBase64Exception::kIllegalFunctionCall
Encodes the input raw memory data stored inside the src
parameter containing the size of src_len
bytes. The encoded data is then stored inside the dest
parameter. Note that dest
needs to be pre-allocated with the correct size that can be calculated using the MTBase64::GetEncodedLength
method.
MTBase64::MTBase64Exception::kIllegalFunctionCall
exception is raised when the input data has a length of 0 bytes.
Type
Function
Args
uint8_t* dest
const uint8_t* src
std::size_t src_len
const IndexTable& table
bool using_padding = true
Returns
Raises
MTBase64::MTBase64Exception::kNotValidBase64
Decodes the input encoded raw memory stored inside src
, containing the size of src_len
bytes. The decoded data is then stored inside the dest
parameter. Note that dest
needs to be pre-allocated with the correct size that can be calculated using the MTBase64::GetDecodedLength
method.
MTBase64::MTBase64Exception::kNotValidBase64
exception is raised when a not valid size of input encoded data is given.
Type
Inline Function
Args
std::size_t encoded_length
Returns
bool
Raises
Checks if the given size of encoded Base64 data is valid when padding is being used.
Type
Inline Function
Args
std::size_t encoded_length
Returns
bool
Raises
Checks if the given size of encoded Base64 data is valid when padding is NOT being used.
Type
Function
Args
std::size_t decoded_length
bool using_padding
Returns
std::size_t
Raises
Calculates and returns the size of the input raw data when encoded with or without used padding.
Type
Function
Args
std::size_t encoded_length
bool using_padding
uint8_t padding_num = 0
Returns
std::size_t
Raises
MTBase64::MTBase64Exception::kNotValidBase64
MTBase64::MTBase64Exception::kIllegalFunctionCall
Calculates and returns the size of the given encoded raw data when decoded with or without used padding.
MTBase64::MTBase64Exception::kIllegalFunctionCall
is raised when padding_num
is larger than 2 (non valid padding number) or when padding_num
is set meanwhile padding isn't being used.
MTBase64::MTBase64Exception::kNotValidBase64
is raised when the given size of the encoded data is not valid, with or without padding.