key_expression: Flatten BIP32 decode error construction
What changed, and why it matters
This commit is a minor code cleanup in the Rust Bitcoin library. It changes how an error message is built when decoding BIP32 extended keys, switching from one nested construction style to two chained calls. The actual behavior and returned error values remain the same. There is no security fix or vulnerability here.
No security action needed. Treat as a normal refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors error construction in Xpriv::decode and Xpub::decode within key_expression/src/bip32.rs. It replaces a single map_err closure that directly constructs XprivDecodeError::Xkey(…) or XpubDecodeError::Xkey(…) with two chained map_err calls: first producing XkeyDecodeError::WrongExtendedKeyLength, then wrapping it via the respective Xkey variant. This is a pure readability/style change with no functional difference.
Changed components
key_expression/src/bip32.rsInspect captured patch +8 / −6
### key_expression/src/bip32.rs
@@ -952,9 +952,10 @@ impl Xpriv {
/// * [`XprivDecodeError::InvalidPrivateKeyPrefix`] if the private key bytes don't start with zero.
/// * [`XprivDecodeError::Secp256k1`] if the private key bytes are not a valid secp secret key.
pub fn decode(data: &[u8]) -> Result<Self, XprivDecodeError> {
- let data: &[u8; 78] = data.try_into().map_err(|_| {
- XprivDecodeError::Xkey(XkeyDecodeError::WrongExtendedKeyLength(data.len()))
- })?;
+ let data: &[u8; 78] = data
+ .try_into()
+ .map_err(|_| XkeyDecodeError::WrongExtendedKeyLength(data.len()))
+ .map_err(XprivDecodeError::Xkey)?;
Self::from_byte_array(data)
}
@@ -1173,9 +1174,10 @@ impl Xpub {
/// * [`XpubDecodeError::UnknownVersion`] if the decoded network value is not main or testnet.
/// * [`XpubDecodeError::Secp256k1`] if the public key bytes are not a valid secp public key.
pub fn decode(data: &[u8]) -> Result<Self, XpubDecodeError> {
- let data: &[u8; 78] = data.try_into().map_err(|_| {
- XpubDecodeError::Xkey(XkeyDecodeError::WrongExtendedKeyLength(data.len()))
- })?;
+ let data: &[u8; 78] = data
+ .try_into()
+ .map_err(|_| XkeyDecodeError::WrongExtendedKeyLength(data.len()))
+ .map_err(XpubDecodeError::Xkey)?;
Self::from_byte_array(data)
}
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.