refactor: Potential fixes for 5 code quality findings in src/aes.rs#808
Conversation
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
There was a problem hiding this comment.
Summary
This PR applies 5 code quality improvements to src/aes.rs. Most changes are working improvements to code clarity and correctness:
✅ Working improvements:
- Simplified module path reference (line 38)
- Simplified
Zeroizingtype fromBox<[u8]>toVec<u8>(line 208) - Enhanced error reporting in
AesReader::validate(lines 224-228) - Replaced
assert!withdebug_assert!and added explicit runtime check (lines 302-311)
- Inconsistent error handling (line 387): The writer discards HMAC initialization error details while the reader includes them, making debugging inconsistent
Recommendation: Address the error handling inconsistency before merge to maintain consistent debugging capabilities across the codebase.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
This reverts commit 812f60a.
There was a problem hiding this comment.
Code Review
This pull request simplifies internal types by using Zeroizing<Vec> instead of boxed slices and cleans up path references. It also updates error handling for HMAC initialization and replaces a hard assertion with a runtime check for finalized states. Feedback indicates that the new check for finalized HMACs is redundant due to existing control flow logic. Additionally, a regression was identified where error details were removed from an HMAC initialization failure message, creating inconsistency with other improvements in the same PR.
| ); | ||
| if self.finalized { | ||
| return Err(Error::new( | ||
| ErrorKind::InvalidData, | ||
| "Tried to use an already finalized HMAC", | ||
| )); | ||
| } | ||
| self.finalized = true; | ||
|
|
||
| // Zip uses HMAC-Sha1-80, which only uses the first half of the hash |
There was a problem hiding this comment.
The debug_assert! and the subsequent if self.finalized check are redundant. Because of the early return at line 284 (if self.data_remaining == 0 { return Ok(0); }), this block is only reachable the first time self.data_remaining reaches zero during a read call. At that point, self.finalized is guaranteed to be false. Any subsequent calls to read will return at line 284 before reaching this logic.
This PR applies 5/5 suggestions from code quality AI findings.