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

Function decrypt_filename

libcppcryptfs/filename/cryptfilename.cpp:278–386  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276
277
278const WCHAR * // returns UNICODE plaintext filename
279decrypt_filename(CryptContext *con, const BYTE *dir_iv, const WCHAR *path, const WCHAR *filename, wstring& storage)
280{
281 static ValidFileNameCharChecker char_checker;
282
283 if (con->GetConfig()->m_PlaintextNames) {
284 storage = filename;
285 return &storage[0];
286 }
287
288 wstring file_without_stream;
289 wstring stream;
290
291 bool have_stream = get_file_stream(filename, &file_without_stream, &stream);
292
293 vector<unsigned char> ctstorage;
294
295 char longname_buf[4096];
296
297 wstring longname_storage;
298
299 if (!wcsncmp(file_without_stream.c_str(), longname_prefix, sizeof(longname_prefix)/sizeof(longname_prefix[0])-1)) {
300 if (con->GetConfig()->m_reverse) {
301 if (decrypt_reverse_longname(con, file_without_stream.c_str(), path, dir_iv, storage))
302 return &storage[0];
303 else
304 return nullptr;
305 } else {
306 wstring fullpath = path;
307 if (fullpath[fullpath.size() - 1] != '\\')
308 fullpath.push_back('\\');
309
310 fullpath += file_without_stream.c_str();
311 fullpath += longname_suffix;
312
313 HANDLE hFile = CreateFile(&fullpath[0], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
314
315 if (hFile == INVALID_HANDLE_VALUE)
316 return NULL;
317
318 DWORD nRead;
319
320 if (!ReadFile(hFile, longname_buf, sizeof(longname_buf)-1, &nRead, NULL)) {
321 CloseHandle(hFile);
322 return NULL;
323 }
324
325 CloseHandle(hFile);
326
327 if (nRead < 1)
328 return NULL;
329
330 longname_buf[nRead] = '\0';
331
332 if (!utf8_to_unicode(longname_buf, longname_storage))
333 return NULL;
334
335 file_without_stream = &longname_storage[0];

Callers 5

convert_fdataFunction · 0.85
decrypt_pathFunction · 0.85
unencrypt_pathFunction · 0.85
get_actual_encryptedFunction · 0.85
decrypt_stream_nameFunction · 0.85

Calls 11

get_file_streamFunction · 0.85
decrypt_reverse_longnameFunction · 0.85
utf8_to_unicodeFunction · 0.85
base64_decodeFunction · 0.85
EmeTransformFunction · 0.85
unPad16Function · 0.85
decrypt_stream_nameFunction · 0.85
GetConfigMethod · 0.80
sizeMethod · 0.80
is_validMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected