MCPcopy Create free account
hub / github.com/apache/trafficserver / DecodeBase64

Function DecodeBase64

lib/yamlcpp/src/binary.cpp:68–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66};
67
68std::vector<unsigned char> DecodeBase64(const std::string &input) {
69 using ret_type = std::vector<unsigned char>;
70 if (input.empty())
71 return ret_type();
72
73 ret_type ret(3 * input.size() / 4 + 1);
74 unsigned char *out = &ret[0];
75
76 unsigned value = 0;
77 for (std::size_t i = 0, cnt = 0; i < input.size(); i++) {
78 if (std::isspace(static_cast<unsigned char>(input[i]))) {
79 // skip newlines
80 continue;
81 }
82 unsigned char d = decoding[static_cast<unsigned char>(input[i])];
83 if (d == 255)
84 return ret_type();
85
86 value = (value << 6) | d;
87 if (cnt % 4 == 3) {
88 *out++ = value >> 16;
89 if (i > 0 && input[i - 1] != '=')
90 *out++ = value >> 8;
91 if (input[i] != '=')
92 *out++ = value;
93 }
94 ++cnt;
95 }
96
97 ret.resize(out - &ret[0]);
98 return ret;
99}
100} // namespace YAML

Callers 2

TESTFunction · 0.85
decodeMethod · 0.85

Calls 3

emptyMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45

Tested by 1

TESTFunction · 0.68