MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / DecodeBase32

Function DecodeBase32

src/utilstrencodings.cpp:212–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

SetSpecialMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 6

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

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68