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

Function read_virtual_file

libcppcryptfs/util/fileutil.cpp:425–458  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

423
424
425bool
426read_virtual_file(CryptContext *con, LPCWSTR FileName, unsigned char *buf, DWORD buflen, LPDWORD pNread, LONGLONG offset)
427{
428 if (rt_is_dir_iv_file(con, FileName)) {
429 wstring dirpath;
430 if (!get_file_directory(FileName, dirpath))
431 return false;
432 BYTE dir_iv[DIR_IV_LEN];
433 if (!derive_path_iv(con, &dirpath[0], dir_iv, TYPE_DIRIV))
434 return false;
435 LONGLONG count = min(DIR_IV_LEN - offset, buflen);
436 if (count <= 0) {
437 *pNread = 0;
438 return true;
439 }
440 memcpy(buf, dir_iv + offset, static_cast<size_t>(count));
441 *pNread = (DWORD)count;
442 return true;
443 } else if (rt_is_name_file(con, FileName)) {
444 string actual_encrypted;
445 if (!get_actual_encrypted(con, FileName, actual_encrypted))
446 return false;
447 LONGLONG count = min(actual_encrypted.length() - offset, buflen);
448 if (count <= 0) {
449 *pNread = 0;
450 return true;
451 }
452 memcpy(buf, &actual_encrypted[0], static_cast<size_t>(count));
453 *pNread = (DWORD)count;
454 return true;
455 } else {
456 return false;
457 }
458}
459
460
461#ifdef _WIN32

Callers 1

Calls 5

rt_is_dir_iv_fileFunction · 0.85
get_file_directoryFunction · 0.85
derive_path_ivFunction · 0.85
rt_is_name_fileFunction · 0.85
get_actual_encryptedFunction · 0.85

Tested by

no test coverage detected