8 #ifndef META_OCEAN_IO_BASE_64_H
9 #define META_OCEAN_IO_BASE_64_H
39 static void encode(
const uint8_t* buffer,
const size_t bufferSize,
Buffer& encodedText);
48 static bool decode(
const uint8_t* encodedText,
const size_t encodedTextSize,
Buffer& buffer);
55 static inline void encode3(
const uint8_t bytes3[3], uint8_t encoded4[4]);
63 static inline bool decode4(
const uint8_t encoded4[4], uint8_t bytes3[3]);
70 static inline uint8_t isEncoded(
const uint8_t encodedValue);
75 static constexpr
const char* encodedCharacters_ =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
82 uint8_t value = (bytes3[0] & 0xFCu) >> 2;
83 ocean_assert(value < 64u);
86 value = uint8_t(((bytes3[0] & 0x03u) << 4) + ((bytes3[1] & 0xF0u) >> 4));
87 ocean_assert(value < 64u);
90 value = uint8_t(((bytes3[1] & 0x0Fu) << 2) + ((bytes3[2] & 0xC0u) >> 6));
91 ocean_assert(value < 64u);
94 value = bytes3[2] & 0x3Fu;
95 ocean_assert(value < 64u);
101 const uint8_t value0 =
isEncoded(encoded4[0]);
102 const uint8_t value1 =
isEncoded(encoded4[1]);
103 const uint8_t value2 =
isEncoded(encoded4[2]);
104 const uint8_t value3 =
isEncoded(encoded4[3]);
106 if (value0 >= 64u || value1 >= 64u || value2 >= 64u || value3 >= 64u)
111 bytes3[0] = uint8_t((value0 << 2) | ((value1 & 0x30u) >> 4));
112 bytes3[1] = uint8_t(((value1 & 0x0Fu) << 4) | ((value2 & 0x3Cu) >> 2));
113 bytes3[2] = uint8_t(((value2 & 0x03u) << 6) | value3);
123 if (encodedValue >=
'A' && encodedValue <=
'Z')
125 return encodedValue -
'A';
127 else if (encodedValue >=
'a' && encodedValue <=
'z')
129 return encodedValue -
'a' + 26u;
131 else if (encodedValue >=
'0' && encodedValue <=
'9')
133 return encodedValue -
'0' + 52u;
135 else if (encodedValue ==
'+')
139 else if (encodedValue ==
'/')
143 else if (encodedValue == 0)
This class implements function to encode binary information to text encoding and vice versa.
Definition: Base64.h:23
static void encode3(const uint8_t bytes3[3], uint8_t encoded4[4])
Encodes 3 bytes of binary information to 4 bytes with text encoding.
Definition: Base64.h:78
std::vector< uint8_t > Buffer
Definition of a vector holding characters.
Definition: Base64.h:29
static bool decode4(const uint8_t encoded4[4], uint8_t bytes3[3])
Decodes 4 bytes with text encoding to 3 bytes of binary information.
Definition: Base64.h:99
static bool decode(const uint8_t *encodedText, const size_t encodedTextSize, Buffer &buffer)
Decodes a text encoding by application of an inverse Base64 to binary information.
static void encode(const uint8_t *buffer, const size_t bufferSize, Buffer &encodedText)
Encodes binary information by application of Base64 to a text encoding.
static constexpr const char * encodedCharacters_
The possible encoded characters.
Definition: Base64.h:75
static uint8_t isEncoded(const uint8_t encodedValue)
Returns whether a given byte is text encoded.
Definition: Base64.h:118
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15