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

Function DecodeBase64

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

Source from the content-addressed store, hash-verified

141}
142
143vector<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 if (pfInvalid)
163 *pfInvalid = false;
164
165 vector<unsigned char> vchRet;
166 vchRet.reserve(strlen(p)*3/4);
167
168 int mode = 0;
169 int left = 0;
170
171 while (1)
172 {
173 int dec = decode64_table[(unsigned char)*p];
174 if (dec == -1) break;
175 p++;
176 switch (mode)
177 {
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 }

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.80
push_backMethod · 0.45
sizeMethod · 0.45

Tested by 3

BOOST_AUTO_TEST_CASEFunction · 0.68
parse_b64der_certFunction · 0.68
paymentServerTestsMethod · 0.68