crypto: Remove all From impls for error types
What changed, and why it matters
This commit is a routine internal code cleanup in the rust-bitcoin library. It removes a convenience conversion (a 'From' implementation) between two error types and replaces it with an explicit error mapping. The actual behavior of signature parsing does not change; it is purely about how errors are wired through the code. There is no indication this fixes a security bug.
No security action required. Treat as normal refactoring/API-hardening commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change removes impl From<InvalidSighashTypeError> for SigFromSliceError in crypto/src/taproot.rs and replaces the implicit ? conversion with an explicit .map_err(SigFromSliceError::SighashType)?. The commit message frames this as an API-flexibility improvement: error types should only implement From<Infallible> and otherwise use map_err to avoid constraining future error-type evolution. The diff is +2/-5 lines and affects only error plumbing, not cryptographic validation logic.
Changed components
crypto/src/taproot.rsSigFromSliceError error plumbingInspect captured patch +2 / −5
diff --git a/crypto/src/taproot.rs b/crypto/src/taproot.rs
index 02c6aa63..1cce0726 100644
--- a/crypto/src/taproot.rs
+++ b/crypto/src/taproot.rs
@@ -58,7 +58,8 @@ impl Signature {
Ok(Self { signature, sighash_type: TapSighashType::Default })
} else if let Ok(signature) = <[u8; 65]>::try_from(sl) {
let (sighash_type, signature) = signature.split_last();
- let sighash_type = TapSighashType::from_consensus_u8(*sighash_type)?;
+ let sighash_type = TapSighashType::from_consensus_u8(*sighash_type)
+ .map_err(SigFromSliceError::SighashType)?;
// per BIP-341: if the sig is 65 bytes long, return Fail if sig[64] = 0x00
// https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#taproot-key-path-spending-signature-validation
if sighash_type == TapSighashType::Default {
@@ -481,10 +482,6 @@ pub mod error {
}
}
- impl From<InvalidSighashTypeError> for SigFromSliceError {
- fn from(err: InvalidSighashTypeError) -> Self { Self::SighashType(err) }
- }
-
/// Error encountered while parsing a Taproot signature from a string.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
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.