bip32: tidy InvalidSeedLengthError trait impls
What changed, and why it matters
This is a minor code cleanup for an error type in the BIP-32 (Bitcoin key derivation) module. It adds a standard 'Copy' trait, a conversion from Rust's 'Infallible' type, an explicit 'no underlying cause' implementation, and slightly clarifies an error message. There is no security fix or behavior change.
No security action required. Treat as routine maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit tidies the trait implementations for InvalidSeedLengthError in key_expression/src/bip32.rs. Changes: derive Copy, add From
Changed components
key_expression/src/bip32.rsInspect captured patch +9 / −3
diff --git a/key_expression/src/bip32.rs b/key_expression/src/bip32.rs
index a62ba7d6..5ad10892 100644
--- a/key_expression/src/bip32.rs
+++ b/key_expression/src/bip32.rs
@@ -1279,7 +1279,7 @@ pub mod error {
}
/// Master seed had an invalid length.
- #[derive(Debug, Clone, PartialEq, Eq)]
+ #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct InvalidSeedLengthError {
pub(crate) length: usize,
}
@@ -1289,14 +1289,20 @@ pub mod error {
pub fn invalid_seed_length(&self) -> usize { self.length }
}
+ impl From<Infallible> for InvalidSeedLengthError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
impl fmt::Display for InvalidSeedLengthError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "invalid BIP-0032 master seed length: {} (expected 16 to 64)", self.length)
+ write!(f, "invalid BIP-0032 master seed length: {} (expected 16 to 64 inclusive)", self.length)
}
}
#[cfg(feature = "std")]
- impl std::error::Error for InvalidSeedLengthError {}
+ impl std::error::Error for InvalidSeedLengthError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
+ }
}
#[cfg(feature = "arbitrary")]
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.