Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/AppInstallerSharedLib/Hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ namespace
return targetFileHash;
}

#ifndef WINGET_DISABLE_FOR_FUZZING
Hash::HashBuffer Hash::ComputeHashFromHandle(HashAlgorithm algorithm, HANDLE fileHandle)
{
constexpr DWORD bufferSize = 1024 * 1024;
Expand All @@ -238,6 +239,7 @@ namespace

return hasher.Get();
}
#endif

bool Hash::AreEqual(const HashBuffer& first, const HashBuffer& second)
{
Expand Down
4 changes: 4 additions & 0 deletions src/AppInstallerSharedLib/Public/winget/Hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ namespace AppInstaller::Cryptography {
// Computes the hash from a given file path.
static HashBuffer ComputeHashFromFile(HashAlgorithm algorithm, const std::filesystem::path& path);

#ifndef WINGET_DISABLE_FOR_FUZZING
// Computes the hash from an open file HANDLE by reading sequentially from the current position.
// The caller retains ownership of the handle.
static HashBuffer ComputeHashFromHandle(HashAlgorithm algorithm, HANDLE fileHandle);
#endif

static std::string ConvertToString(const HashBuffer& hashBuffer, size_t hashBufferSizeInBytes);

Expand Down Expand Up @@ -156,10 +158,12 @@ namespace AppInstaller::Cryptography {
return Hash::ComputeHashFromFile(Algorithm, path);
}

#ifndef WINGET_DISABLE_FOR_FUZZING
static HashBuffer ComputeHashFromHandle(HANDLE fileHandle)
{
return Hash::ComputeHashFromHandle(Algorithm, fileHandle);
}
#endif

static std::string ConvertToString(const HashBuffer& hashBuffer)
{
Expand Down
Loading