MCPcopy Create free account
hub / github.com/PDAL/PDAL / base64_decode

Method base64_decode

pdal/util/Utils.cpp:268–320  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266
267
268std::vector<uint8_t> Utils::base64_decode(std::string const& encoded_string)
269{
270 const std::string base64_chars =
271 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
272 "abcdefghijklmnopqrstuvwxyz"
273 "0123456789+/";
274
275 std::string::size_type in_len = encoded_string.size();
276 int i = 0;
277 int j = 0;
278 int in_ = 0;
279 unsigned char char_array_4[4], char_array_3[3];
280 std::vector<uint8_t> ret;
281
282 while (in_len-- && (encoded_string[in_] != '=') && is_base64(encoded_string[in_]))
283 {
284 char_array_4[i++] = encoded_string[in_];
285 in_++;
286 if (i == 4)
287 {
288 for (i = 0; i <4; i++)
289 char_array_4[i] = static_cast<unsigned char>(
290 base64_chars.find(char_array_4[i]));
291
292 char_array_3[0] = (char_array_4[0] << 2) +
293 ((char_array_4[1] & 0x30) >> 4);
294 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) +
295 ((char_array_4[2] & 0x3c) >> 2);
296 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
297
298 for (i = 0; (i < 3); i++)
299 ret.push_back(char_array_3[i]);
300 i = 0;
301 }
302 }
303
304 if (i)
305 {
306 for (j = i; j <4; j++)
307 char_array_4[j] = 0;
308
309 for (j = 0; j <4; j++)
310 char_array_4[j] = static_cast<unsigned char>(base64_chars.find(char_array_4[j]));
311
312 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
313 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
314 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
315
316 for (j = 0; (j < i - 1); j++)
317 ret.push_back(char_array_3[j]);
318 }
319 return ret;
320}
321
322
323FILE* Utils::portable_popen(const std::string& command, const std::string& mode)

Callers

nothing calls this directly

Calls 3

is_base64Function · 0.85
sizeMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected