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

Function DecodeBase32

src/util/strencodings.cpp:220–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218}
219
220std::vector<unsigned char> DecodeBase32(const char* p, bool* pf_invalid)
221{
222 static const int8_t decode32_table[256]{
223 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
224 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
225 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1,
226 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
227 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 0, 1, 2,
228 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
229 23, 24, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
230 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
231 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
232 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
233 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
234 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
235 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
236 };
237
238 const char* e = p;
239 std::vector<uint8_t> val;
240 val.reserve(strlen(p));
241 while (*p != 0) {
242 int x = decode32_table[(unsigned char)*p];
243 if (x == -1) break;
244 val.push_back(uint8_t(x));
245 ++p;
246 }
247
248 std::vector<unsigned char> ret;
249 ret.reserve((val.size() * 5) / 8);
250 bool valid = ConvertBits<5, 8, false>([&](unsigned char c) { ret.push_back(c); }, val.begin(), val.end());
251
252 const char* q = p;
253 while (valid && *p != 0) {
254 if (*p != '=') {
255 valid = false;
256 break;
257 }
258 ++p;
259 }
260 valid = valid && (p - e) % 8 == 0 && p - q < 8;
261 if (pf_invalid) *pf_invalid = !valid;
262
263 return ret;
264}
265
266std::string DecodeBase32(const std::string& str, bool* pf_invalid)
267{

Callers 4

SetTorMethod · 0.85
SetI2PMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGET_INITFunction · 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