MCPcopy Create free account
hub / github.com/LegacyUpdate/LegacyUpdate / calculateFileSha256

Function calculateFileSha256

nsisplugin/VerifyFileHash.c:38–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38static BOOL calculateFileSha256(const LPWSTR path, uint8_t hash[SIZE_OF_SHA_256_HASH]) {
39 HANDLE file = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
40 if (file == INVALID_HANDLE_VALUE) {
41 return FALSE;
42 }
43
44 struct Sha_256 sha256;
45 sha_256_init(&sha256, hash);
46
47 uint8_t buffer[8192];
48 DWORD bytesRead = 0;
49 while (ReadFile(file, buffer, sizeof(buffer), &bytesRead, NULL) && bytesRead > 0) {
50 sha_256_write(&sha256, buffer, bytesRead);
51 }
52
53 sha_256_close(&sha256);
54 CloseHandle(file);
55 return TRUE;
56}
57
58PLUGIN_METHOD(VerifyFileHash) {
59 PLUGIN_INIT();

Callers 1

VerifyFileHash.cFile · 0.85

Calls 3

sha_256_initFunction · 0.85
sha_256_writeFunction · 0.85
sha_256_closeFunction · 0.85

Tested by

no test coverage detected