22 const unsigned char alphabet[64+1] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
36 for (
size_t i=0;i<inputData.size();i++)
44 outString.push_back(
alphabet[bits >> 18] );
45 outString.push_back(
alphabet[(bits >> 12) & 0x3f] );
46 outString.push_back(
alphabet[(bits >> 6) & 0x3f]);
47 outString.push_back(
alphabet[bits & 0x3f]);
51 outString.push_back(
'\n');
65 bits <<= 16 - (8 * char_count);
66 outString.push_back(
alphabet[bits >> 18]);
67 outString.push_back(
alphabet[(bits >> 12) & 0x3f]);
71 outString.push_back(
'=');
72 outString.push_back(
'=');
76 outString.push_back(
alphabet[(bits >> 6) & 0x3f]);
77 outString.push_back(
'=');
80 outString.push_back(
'\n');
89 static bool inalphabet[256];
90 static char decoder[256];
92 static bool tablesBuilt =
false;
97 for (
int i = (
sizeof(
alphabet)) - 1; i >= 0 ; i--)
105 outData.reserve( inString.size() *
round(3.0/4.0) );
111 bool finish_flag_found =
false;
113 for (
size_t i=0;i<inString.size();i++)
115 const unsigned char c = inString[i];
119 finish_flag_found =
true;
129 outData.push_back((bits >> 16));
130 outData.push_back(((bits >> 8) & 0xff));
131 outData.push_back((bits & 0xff));
139 if (!finish_flag_found)
143 std::cerr <<
format(
"[decodeBase64] ERROR: base64 encoding incomplete, at least %d bits truncated", ((4 - char_count) * 6)) << std::endl;
152 std::cerr <<
"[decodeBase64] ERROR: base64 encoding incomplete, at least 2 bits missing" << std::endl;
156 outData.push_back((bits >> 10));
159 outData.push_back((bits >> 16));
160 outData.push_back(((bits >> 8) & 0xff));
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
std::vector< uint8_t > vector_byte
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
void BASE_IMPEXP encodeBase64(const vector_byte &inputData, std::string &outString)
Encode a sequence of bytes as a string in base-64.
bool BASE_IMPEXP decodeBase64(const std::string &inString, vector_byte &outData)
Decode a base-64 string into the original sequence of bytes.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
GLsizei const GLchar ** string
const unsigned char alphabet[64+1]
int round(const T value)
Returns the closer integer (int) to x.