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

Function base64_encode

libcppcryptfs/util/util.cpp:295–347  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293
294
295const char *
296base64_encode(const BYTE *data, DWORD datalen, string& storage, bool urlTransform, bool padding)
297{
298
299 if (!urlTransform) {
300 _ASSERT(padding);
301 }
302
303 if (!data || datalen < 1)
304 return NULL;
305
306 int base64len = (int)datalen*2;
307
308 char *base64str = NULL;
309
310 BOOL bResult = FALSE;
311
312 TempBuffer<char, 4096> base64(base64len + 1);
313
314 if (base64str = base64.get()) {
315
316 // ATL Base64Encode() is supposedly way faster than CryptBinaryToString()
317
318 bResult = Base64Encode(data, (int)datalen, base64str, &base64len, ATL_BASE64_FLAG_NOCRLF);
319
320 // ATL Base64Encode() doesn't null terminate the string
321 if (bResult)
322 base64str[base64len] = '\0';
323
324 } else {
325 bResult = FALSE;
326 }
327 if (bResult) {
328
329 if (urlTransform) {
330 size_t len = strlen(base64str);
331 size_t i;
332 for (i = 0; i < len; i++) {
333 if (base64str[i] == '+')
334 base64str[i] = '-';
335 else if (base64str[i] == '/')
336 base64str[i] = '_';
337 }
338 }
339 storage = base64str;
340
341 if (!padding)
342 remove_base64_padding(storage);
343 return storage.c_str();
344 } else {
345 return NULL;
346 }
347}
348
349const WCHAR *
350base64_encode(const BYTE *data, DWORD datalen, wstring& storage, bool urlTransform, bool padding)

Callers 3

encrypt_string_gcmFunction · 0.85
encrypt_keyMethod · 0.85
encrypt_filenameFunction · 0.85

Calls 3

remove_base64_paddingFunction · 0.85
sizeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected