hashcrypt: minimize panic code paths#528
hashcrypt: minimize panic code paths#528jerrysxie merged 6 commits intoOpenDevicePartnership:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the hashcrypt module to replace panic-based error handling with Result-based error handling, introducing a new Error enum and updating all public APIs to return Result<(), Error>.
- Introduces a new
Errorenum with anUnsupportedConfigurationvariant - Converts internal helper methods to use bounds checking with error returns instead of direct indexing
- Updates all public methods (
submit_blocks,finalize,hash) for both blocking and async variants to return Results
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/hashcrypt/mod.rs |
Adds the new Error enum with UnsupportedConfiguration variant and defmt support |
src/hashcrypt/hasher.rs |
Converts internal methods and public APIs to return Results, replacing panics with error handling (except one remaining panic in async transfer) |
examples/rt685s-evk/src/bin/sha256.rs |
Updates example to handle Results with .unwrap() calls on hash operations |
examples/rt685s-evk/src/bin/sha256-async.rs |
Updates async example to handle Results with .unwrap() calls on hash operations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
* Fix format * Replace panic! with error return
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 4 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Announced on Zulip: #embedded-controller > embassy-imxrt breaking hashcrypt API changes @ 💬 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request enhances error handling in the
hashcrypthasher implementation by introducing a unifiedErrortype and updating relevant methods to returnResultinstead of panicking. This makes the code more robust, especially for invalid input scenarios, and improves its safety and reliability in both blocking and asynchronous hashing modes.Error handling improvements:
Errorenum insrc/hashcrypt/mod.rsto represent unsupported configurations and updated code to use this error type instead of panicking.Hasher(such asinit_final_data,init_final_block, andinit_final_len) to returnResult<(), Error>and propagate errors instead of panicking on invalid buffer access.Blocking hasher API changes:
Hasherimplementation (submit_blocks,finalize,hash) to returnResultand handle errors gracefully, replacing panics with error returns for invalid input lengths.Async hasher API changes:
Hashermethods (transfer,submit_blocks,finalize,hash) to returnResultand propagate errors, ensuring safe handling of invalid conditions such as missing DMA channels or incorrect data lengths. [1] [2] [3]General code safety improvements: