Replace usage of secp256k1::Error with new error in ecdsa
What changed, and why it matters
This commit is a straightforward internal cleanup in the rust-bitcoin library. It swaps one error type for another when an ECDSA signature fails to decode from DER format. The behavior of signature parsing does not change; only the name and contents of the error value reported to callers are different. There is no indication this fixes a security bug or introduces a vulnerability.
No security action required. Treat as a normal API refactor; verify downstream code that pattern-matches on `DecodeError::Secp256k1` updates to `DecodeError::InvalidDer` if the error type is part of the public API.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change replaces DecodeError::Secp256k1(secp256k1::Error) with DecodeError::InvalidDer(InvalidDerError) in crypto/src/ecdsa.rs. The underlying call remains secp256k1::ecdsa::Signature::from_der(sig), and the secp256k1 error is still discarded (|_|). This is an API/error-typing refactor that removes a public dependency on secp256k1::Error in the returned error type. No logic, validation, or cryptographic handling is altered.
Changed components
crypto/src/ecdsa.rsDecodeError enumSignature::from_sliceInspect captured patch +7 / −7
diff --git a/crypto/src/ecdsa.rs b/crypto/src/ecdsa.rs
index b1f04351..6277f5e0 100644
--- a/crypto/src/ecdsa.rs
+++ b/crypto/src/ecdsa.rs
@@ -60,13 +60,13 @@ impl Signature {
/// # Errors
///
/// * [`DecodeError::EmptySignature`] if the slice is empty.
- /// * [`DecodeError::Secp256k1`] if the slice cannot be decoded to an ECDSA signature.
+ /// * [`DecodeError::InvalidDer`] if the slice is not a valid DER encoding for an ECDSA signature.
pub fn from_slice(sl: &[u8]) -> Result<Self, DecodeError> {
let (sighash_type, sig) = sl.split_last().ok_or(DecodeError::EmptySignature)?;
let sighash_type = EcdsaSighashType::from_standard(u32::from(*sighash_type))
.map_err(DecodeError::SighashType)?;
- let signature =
- secp256k1::ecdsa::Signature::from_der(sig).map_err(DecodeError::Secp256k1)?;
+ let signature = secp256k1::ecdsa::Signature::from_der(sig)
+ .map_err(|_| DecodeError::InvalidDer(InvalidDerError))?;
Ok(Self { signature, sighash_type })
}
@@ -285,8 +285,8 @@ pub mod error {
SighashType(NonStandardSighashTypeError),
/// Signature was empty.
EmptySignature,
- /// A secp256k1 error.
- Secp256k1(secp256k1::Error),
+ /// Bad DER encoding for ECDSA signature.
+ InvalidDer(InvalidDerError),
}
impl From<Infallible> for DecodeError {
@@ -298,7 +298,7 @@ pub mod error {
match self {
Self::SighashType(ref e) => write_err!(f, "non-standard signature hash type"; e),
Self::EmptySignature => write!(f, "empty ECDSA signature"),
- Self::Secp256k1(ref e) => write_err!(f, "secp256k1"; e),
+ Self::InvalidDer(ref e) => write_err!(f, "bad DER encoding for ECDSA signature"; e),
}
}
}
@@ -307,7 +307,7 @@ pub mod error {
impl std::error::Error for DecodeError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
- Self::Secp256k1(ref e) => Some(e),
+ Self::InvalidDer(ref e) => Some(e),
Self::SighashType(ref e) => Some(e),
Self::EmptySignature => None,
}
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.