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

Function DecodeBase64

src/utilstrencodings.cpp:143–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 7

RPCAuthorizedFunction · 0.85
DecodePSBTFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
parse_b64der_certFunction · 0.85
paymentServerTestsMethod · 0.85
verifymessageFunction · 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 3

BOOST_AUTO_TEST_CASEFunction · 0.68
parse_b64der_certFunction · 0.68
paymentServerTestsMethod · 0.68