You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduces a reusable CNG-backed hash abstraction in winget/Hash.h while preserving the existing AppInstaller::Utility::SHA256 API. This follow-up also clarifies the algorithm-bound alias name and explicitly preserves move support for hashers while disallowing copying.
🔗 References
Related to #5771; this PR does not implement SHA3-256 or close that issue.
🔍 Validation
src\x64\Debug\AppInstallerCLITests\AppInstallerCLITests.exe '[Cryptography]' — passed: 12 assertions in 5 test cases.
The author reports that the test project was built and the cryptography tests were run successfully.
* Adds new Hash.cpp in SharedLib to provide base class access to BCrypt hashing functionality
* Moves implementation from SHA256 into the the base class
* Leaves the SHA256 namespace as a wrapper around the base class
Add a HashAlgorithmTraits/AlgorithmHash template in AppInstallerHash.h
that binds the generic Hash engine to a specific algorithm at compile
time, exposing the full SHA256-style API (Add, Get, ComputeHash*,
ConvertTo*, AreEqual) without per-function forwarding code.
Reduce SHA256 to an empty class deriving from
AlgorithmHash<HashAlgorithm::Sha256>, and remove the now-unnecessary
SHA256.cpp along with its project/filter entries.
Adding a new algorithm such as SHA3-256 will only require a new
HashAlgorithm enumerator, a HashAlgorithmTraits specialization, CNG
metadata in Hash.cpp, and an empty named class, with no forwarding
boilerplate.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
Restored concise comments describing opening the CNG algorithm provider, obtaining the hash length, creating the hash handle, stream badbit behavior, and the 1 MB buffer.
The reason will be displayed to describe this comment to others. Learn more.
I know I'm being nitpicky and it's not a big deal if you keep this as-is, but I would prefer to keep the same level of comments we had before unless there is a reason to delete them, and also keep the same formatting. For example, making this section:
// Open an algorithm handleTHROW_IF_NTSTATUS_FAILED_MSG(BCryptOpenAlgorithmProvider(
&algHandle, // Alg Handle pointer
algorithmInfo.CngAlgorithmId, // Cryptographic Algorithm name (null terminated unicode string)nullptr, // Provider name; if null, the default provider is loaded0), // Flags
"failed opening %hs algorithm provider",
algorithmInfo.Name);
I'm hoping that would make git see this as a rename instead of a new file, and it would give us a nicer diff/blame.
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🟡 Changes recommended
The implementation can silently produce incorrect hashes on oversized input or read failure, and it removes the legacy public include path despite the compatibility goal.
This alias does not fully preserve the existing source API because the public AppInstallerSHA256.h header that existing consumers include is deleted. All in-repo includes were migrated, but out-of-tree code will fail before it can see this compatibility alias. Keep AppInstallerSHA256.h as a forwarding header that includes winget/Hash.h (and retain it in the project) while deprecating the old include path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📖 Description
Introduces a reusable CNG-backed hash abstraction in
winget/Hash.hwhile preserving the existingAppInstaller::Utility::SHA256API. This follow-up also clarifies the algorithm-bound alias name and explicitly preserves move support for hashers while disallowing copying.🔗 References
Related to #5771; this PR does not implement SHA3-256 or close that issue.
🔍 Validation
src\x64\Debug\AppInstallerCLITests\AppInstallerCLITests.exe '[Cryptography]'— passed: 12 assertions in 5 test cases.✅ Checklist
🤖 AI Assistance
📋 Issue Type