MCPcopy Create free account
hub / github.com/ElementsProject/elements / DecodeBase64

Function DecodeBase64

src/util/strencodings.cpp:142–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142std::vector<unsigned char> DecodeBase64(const char* p, bool* pf_invalid)
143{
144 static const int8_t decode64_table[256]{
145 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
146 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
147 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1,
148 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
149 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28,
150 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
151 49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
152 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
153 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
154 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
155 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
156 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
157 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
158 };
159
160 const char* e = p;
161 std::vector<uint8_t> val;
162 val.reserve(strlen(p));
163 while (*p != 0) {
164 int x = decode64_table[(unsigned char)*p];
165 if (x == -1) break;
166 val.push_back(uint8_t(x));
167 ++p;
168 }
169
170 std::vector<unsigned char> ret;
171 ret.reserve((val.size() * 3) / 4);
172 bool valid = ConvertBits<6, 8, false>([&](unsigned char c) { ret.push_back(c); }, val.begin(), val.end());
173
174 const char* q = p;
175 while (valid && *p != 0) {
176 if (*p != '=') {
177 valid = false;
178 break;
179 }
180 ++p;
181 }
182 valid = valid && (p - e) % 4 == 0 && p - q < 4;
183 if (pf_invalid) *pf_invalid = !valid;
184
185 return ret;
186}
187
188std::string DecodeBase64(const std::string& str, bool* pf_invalid)
189{

Callers 7

DecodeI2PBase64Function · 0.85
RPCAuthorizedFunction · 0.85
DecodeBase64PSBTFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGET_INITFunction · 0.85
gotoLoadPSBTMethod · 0.85
MessageVerifyFunction · 0.85

Calls 7

ValidAsCStringFunction · 0.85
reserveMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
dataMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68