Put sha256 context init/shutdown under a RAII wrapper#7251
Merged
Conversation
1f9175a to
6fe6f69
Compare
achamayou
reviewed
Sep 4, 2025
achamayou
reviewed
Sep 4, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a RAII wrapper (Sha256ContextGuard) to replace manual initialization and cleanup calls for the OpenSSL SHA256 context management, improving resource safety and reducing boilerplate code.
- Replaced manual
ccf::crypto::openssl_sha256_init()andccf::crypto::openssl_sha256_shutdown()calls with RAII pattern - Added
Sha256ContextGuardclass that handles initialization in constructor and cleanup in destructor - Updated documentation to reflect the new API usage pattern
Reviewed Changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| include/ccf/crypto/openssl_init.h | Defines new Sha256ContextGuard RAII wrapper class |
| src/crypto/openssl/hash.cpp | Implements the guard constructor/destructor and improves error handling |
| tests/perf-system/submitter/submit.cpp | Migrates from manual init/shutdown calls to RAII guard |
| src/pal/test/snp_ioctl_test.cpp | Migrates test code to use the new RAII pattern |
| src/pal/test/snp_attestation_validation.cpp | Migrates test code to use the new RAII pattern |
| src/node/test/* | Multiple test files migrated to use the RAII pattern |
| src/kv/test/* | Multiple test files migrated to use the RAII pattern |
| src/indexing/test/indexing.cpp | Migrates test code to use the RAII pattern |
| src/host/test/ledger.cpp | Migrates test code to use the RAII pattern |
| src/host/run.cpp | Migrates main application code to use the RAII pattern |
| src/enclave/enclave.h | Migrates enclave initialization to use the RAII pattern |
| src/crypto/test/* | Multiple crypto test files migrated to use the RAII pattern |
| doc/build_apps/get_started.rst | Updates documentation to reflect new API usage |
| CHANGELOG.md | Documents the API change |
Comments suppressed due to low confidence (1)
src/node/test/history_bench.cpp:1
- This line should call
openssl_sha256_shutdown()instead ofopenssl_sha256_init(). The original code had a shutdown call here, but the replacement is incorrect.
// Copyright (c) Microsoft Corporation. All rights reserved.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
eddyashton
reviewed
Sep 4, 2025
6fe6f69 to
61e3e53
Compare
eddyashton
approved these changes
Sep 5, 2025
eddyashton
pushed a commit
to eddyashton/CCF
that referenced
this pull request
Oct 10, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Because why not?..
Do not merge before: