MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / base64_decode

Function base64_decode

libcppcryptfs/util/util.cpp:196–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194}
195
196bool
197base64_decode(const char *str, vector<unsigned char>& storage, bool urlTransform, bool padding)
198{
199 if (!urlTransform) {
200 _ASSERT(padding);
201 }
202
203 string padded_storage;
204
205 if (!padding)
206 str = add_base64_padding(str, padded_storage);
207
208 size_t str_len;
209
210 if (!str || (str_len = strlen(str)) < 1)
211 return false;
212
213 char *p = NULL;
214
215 if (urlTransform) {
216
217 p = _strdup(str);
218
219 if (!p)
220 return false;
221 }
222
223 if (urlTransform) {
224
225 size_t i;
226 for (i = 0; i < str_len; i++) {
227 if (p[i] == '-')
228 p[i] = '+';
229 else if (p[i] == '_')
230 p[i] = '/';
231 }
232 }
233
234 DWORD len = (DWORD)str_len;
235
236 BOOL bResult = FALSE;
237
238 try {
239
240 storage.resize(len);
241
242 // CryptStringToBinary() is supposedly a little faster than ATL Base64Decode()
243
244 bResult = CryptStringToBinaryA(p ? p : str, 0, CRYPT_STRING_BASE64, &storage[0], &len, NULL, NULL);
245
246 } catch (...) {
247 bResult = FALSE;
248 }
249
250 if (p)
251 ::free(p);
252
253 if (bResult) {

Callers 3

decrypt_string_gcmFunction · 0.85
readMethod · 0.85
decrypt_filenameFunction · 0.85

Calls 1

add_base64_paddingFunction · 0.85

Tested by

no test coverage detected