MCPcopy Create free account
hub / github.com/LUX-Core/lux / DecodeBase64

Function DecodeBase64

src/utilstrencodings.cpp:146–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)
147{
148 static const int decode64_table[256] =
149 {
150 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
151 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
152 -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1,
153 -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
154 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28,
155 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
156 49, 50, 51, -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, -1, -1, -1, -1,
160 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
161 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
162 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
163
164 if (pfInvalid)
165 *pfInvalid = false;
166
167 vector<unsigned char> vchRet;
168 vchRet.reserve(strlen(p) * 3 / 4);
169
170 int mode = 0;
171 int left = 0;
172
173 while (1) {
174 int dec = decode64_table[(unsigned char)*p];
175 if (dec == -1) break;
176 p++;
177 switch (mode) {
178 case 0: // we have no bits and get 6
179 left = dec;
180 mode = 1;
181 break;
182
183 case 1: // we have 6 bits and keep 4
184 vchRet.push_back((left << 2) | (dec >> 4));
185 left = dec & 15;
186 mode = 2;
187 break;
188
189 case 2: // we have 4 bits and get 6, we keep 2
190 vchRet.push_back((left << 4) | (dec >> 2));
191 left = dec & 3;
192 mode = 3;
193 break;
194
195 case 3: // we have 2 bits and get 6
196 vchRet.push_back((left << 6) | dec);
197 mode = 0;
198 break;
199 }
200 }
201
202 if (pfInvalid)
203 switch (mode) {

Callers 6

RPCAuthorizedFunction · 0.85
verifymessageFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
parse_b64der_certFunction · 0.85
paymentServerTestsMethod · 0.85

Calls 3

reserveMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by 3

BOOST_AUTO_TEST_CASEFunction · 0.68
parse_b64der_certFunction · 0.68
paymentServerTestsMethod · 0.68