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

Function DecodeBase32

src/util/strencodings.cpp:163–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161}
162
163std::optional<std::vector<unsigned char>> DecodeBase32(std::string_view str)
164{
165 static const int8_t decode32_table[256]{
166 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
167 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
168 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1,
169 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
170 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 0, 1, 2,
171 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
172 23, 24, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
173 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
174 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
175 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
176 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
177 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
178 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
179 };
180
181 if (str.size() % 8 != 0) return {};
182 /* 1, 3, 4, or 6 padding '=' suffix characters are permitted. */
183 if (str.size() >= 1 && str.back() == '=') str.remove_suffix(1);
184 if (str.size() >= 2 && str.substr(str.size() - 2) == "==") str.remove_suffix(2);
185 if (str.size() >= 1 && str.back() == '=') str.remove_suffix(1);
186 if (str.size() >= 2 && str.substr(str.size() - 2) == "==") str.remove_suffix(2);
187
188 std::vector<unsigned char> ret;
189 ret.reserve((str.size() * 5) / 8);
190 bool valid = ConvertBits<5, 8, false>(
191 [&](unsigned char c) { ret.push_back(c); },
192 str.begin(), str.end(),
193 [](char c) { return decode32_table[uint8_t(c)]; }
194 );
195
196 if (!valid) return {};
197
198 return ret;
199}
200
201std::string FormatParagraph(std::string_view in, size_t width, size_t indent)
202{

Callers 4

SetTorMethod · 0.85
SetI2PMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGETFunction · 0.85

Calls 6

sizeMethod · 0.45
backMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGETFunction · 0.68