24 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
30 const std::vector<uint8_t>& inputData,
std::string& outString)
33 outString.reserve(inputData.size() *
mrpt::round(4.0 / 3.0));
39 for (
size_t i = 0; i < inputData.size(); i++)
47 outString.push_back(
alphabet[bits >> 18]);
48 outString.push_back(
alphabet[(bits >> 12) & 0x3f]);
49 outString.push_back(
alphabet[(bits >> 6) & 0x3f]);
50 outString.push_back(
alphabet[bits & 0x3f]);
54 outString.push_back(
'\n');
68 bits <<= 16 - (8 * char_count);
69 outString.push_back(
alphabet[bits >> 18]);
70 outString.push_back(
alphabet[(bits >> 12) & 0x3f]);
74 outString.push_back(
'=');
75 outString.push_back(
'=');
79 outString.push_back(
alphabet[(bits >> 6) & 0x3f]);
80 outString.push_back(
'=');
82 if (cols > 0) outString.push_back(
'\n');
90 const std::string& inString, std::vector<uint8_t>& outData)
92 static bool inalphabet[256];
93 static char decoder[256];
95 static bool tablesBuilt =
false;
100 for (
int i = (
sizeof(
alphabet)) - 1; i >= 0; i--)
108 outData.reserve(inString.size() *
round(3.0 / 4.0));
114 bool finish_flag_found =
false;
116 for (
size_t i = 0; i < inString.size(); i++)
118 const unsigned char c = inString[i];
122 finish_flag_found =
true;
125 if (!inalphabet[
c])
continue;
131 outData.push_back((bits >> 16));
132 outData.push_back(((bits >> 8) & 0xff));
133 outData.push_back((bits & 0xff));
141 if (!finish_flag_found)
145 std::cerr <<
"[decodeBase64] ERROR: base64 encoding incomplete, at"
147 << ((4 - char_count) * 6) <<
"bits truncated."
157 std::cerr <<
"[decodeBase64] ERROR: base64 encoding "
158 "incomplete, at least 2 bits missing"
163 outData.push_back((bits >> 10));
166 outData.push_back((bits >> 16));
167 outData.push_back(((bits >> 8) & 0xff));