Add Crypto Engine error codes to HsmError/TborStatus - #697
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
There is a concrete rustdoc formatting defect in the updated documentation comment, and the new CPT status mapping logic in api/lib is currently untested despite existing unit test coverage in that module.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR extends the AZIHSM error-code surface to directly represent CryptoController (CPT) engine-originated errors across firmware PAL traits (HsmError), the TBOR wire status mirror (TborStatus), and the host API layer, avoiding an extra translation step.
Changes:
- Added the CPT (0x090A_xxxx) error-code range to firmware
HsmErrorand DDITborStatus, preserving numeric values and names. - Added host-facing
HsmErrorvariants and a 1:1DdiError::TborStatus(...) -> HsmErrormapping for the CPT statuses. - Added a firmware-side unit test pinning CPT numeric values to the external source of truth.
File summaries
| File | Description |
|---|---|
| fw/pal/traits/src/error.rs | Adds CPT error variants to FW HsmError and a unit test asserting the numeric values. |
| ddi/tbor/types/src/status.rs | Adds CPT status variants to TborStatus to mirror FW error codes on the wire. |
| api/lib/src/error.rs | Adds host-facing HsmError variants corresponding to CPT statuses. |
| api/lib/src/ddi/mod.rs | Maps CPT TborStatus values 1:1 into host HsmError variants. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| DdiError::TborStatus(TborStatus::CryptoNotInitialized) => { | ||
| HsmError::CryptoNotInitialized | ||
| } | ||
| DdiError::TborStatus(TborStatus::CryptoBufferTooSmall) => { | ||
| HsmError::CryptoBufferTooSmall |
| /// All remaining `DdiError` variants are logged and collapsed into | ||
| /// `HsmError::DdiCmdFailure`. | ||
| /// | ||
| /// Every `TborStatus::Crypto*`/`CryptoCpt*` CPT (`CryptoController`)/// status is mapped 1:1 to its own `HsmError` variant of the same name,/// mirroring the FW-side range verbatim. |
Mirror Crypto Engine error code range (0x090A_xxxx) into HsmError and its TborStatus wire mirror, using the same names and numeric values, so the engine originated codes are directly representable without a translation layer. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
13f98bb to
54a5466
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The changes consistently add and validate the CPT error-code range across FW, wire status, and host mapping layers without altering existing codes or introducing behavioral regressions.
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Lite
| /// Every `TborStatus::Crypto*`/`CryptoCpt*` CPT (`CryptoController`) status is | ||
| /// mapped 1:1 to its own `HsmError` variant of the same name, mirroring the | ||
| /// FW-side range verbatim. |
| // -- CPT (CryptoController) host-facing errors ---------- | ||
| // 1:1 mirror of the TborStatus/HsmError (FW) CPT range. | ||
|
|
Mirror Crypto Engine error code range (0x090A_xxxx) into HsmError and its TborStatus wire mirror, using the same names and numeric values, so the engine originated codes are directly representable without a translation layer.