rust/keystore: simplify securechip error propagation
What changed, and why it matters
This commit is a small internal code cleanup in the BitBox02 firmware's Rust keystore module. It moves the conversion of securechip error codes into a standard Rust trait implementation (`From`) so the same logic can be reused with the `?` operator. There is no change to user-facing behavior, cryptographic operations, or security boundaries.
No security action required. This is a non-functional refactor. Routine code review and merge are sufficient.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors error handling in rust/keystore. Previously, stretch_retained_seed_encryption_key() manually mapped securechip::Error variants to keystore::Error::SecureChip(...) via map_err. The patch adds a From<crate::securechip::Error> implementation for keystore::Error that performs the identical mapping, then replaces the explicit map_err with ?. The conversion logic is unchanged: securechip::Error::SecureChip(sc_err) maps to Error::SecureChip(sc_err as i32) and securechip::Error::Status(status) maps to Error::SecureChip(status).
Changed components
src/rust/bitbox02-rust/src/keystore.rssrc/rust/bitbox02/src/keystore.rsInspect captured patch +10 / −4
diff --git a/src/rust/bitbox02-rust/src/keystore.rs b/src/rust/bitbox02-rust/src/keystore.rs
index 38e4f81..c099df0 100644
--- a/src/rust/bitbox02-rust/src/keystore.rs
+++ b/src/rust/bitbox02-rust/src/keystore.rs
@@ -392,10 +392,7 @@ pub fn stretch_retained_seed_encryption_key(
) -> Result<zeroize::Zeroizing<Vec<u8>>, Error> {
let salted_in = crate::salt::hash_data(encryption_key, purpose_in).map_err(|_| Error::Salt)?;
- let kdf = securechip::kdf(salted_in.as_slice()).map_err(|err| match err {
- securechip::Error::SecureChip(sc_err) => Error::SecureChip(sc_err as i32),
- securechip::Error::Status(status) => Error::SecureChip(status),
- })?;
+ let kdf = securechip::kdf(salted_in.as_slice())?;
let salted_out =
crate::salt::hash_data(encryption_key, purpose_out).map_err(|_| Error::Salt)?;
diff --git a/src/rust/bitbox02/src/keystore.rs b/src/rust/bitbox02/src/keystore.rs
index b74f5c5..62d1418 100644
--- a/src/rust/bitbox02/src/keystore.rs
+++ b/src/rust/bitbox02/src/keystore.rs
@@ -43,6 +43,15 @@ pub enum Error {
StretchRetainedSeedKey,
}
+impl core::convert::From<crate::securechip::Error> for Error {
+ fn from(error: crate::securechip::Error) -> Self {
+ match error {
+ crate::securechip::Error::SecureChip(sc_err) => Error::SecureChip(sc_err as i32),
+ crate::securechip::Error::Status(status) => Error::SecureChip(status),
+ }
+ }
+}
+
impl core::convert::From<keystore_error_t> for Error {
fn from(error: keystore_error_t) -> Self {
match error {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.