diff --git a/bitcoin/src/crypto/ecdsa.rs b/bitcoin/src/crypto/ecdsa.rs index 646c2168c0..6d497bee4a 100644 --- a/bitcoin/src/crypto/ecdsa.rs +++ b/bitcoin/src/crypto/ecdsa.rs @@ -99,54 +99,42 @@ impl FromStr for Signature { } impl TryFrom<&str> for Signature { - type Error = Error; + type Error = ParseSignatureError; fn try_from(s: &str) -> Result { - let bytes = Vec::from_hex(s)?; - let (sighash_byte, signature) = bytes.split_last().ok_or(Error::EmptySignature)?; - Ok(Signature { - signature: secp256k1::ecdsa::Signature::from_der(signature)?, - sighash_type: EcdsaSighashType::from_standard(*sighash_byte as u32)?, - }) + Self::from_str(s) + } +} + +impl TryFrom for Signature { + type Error = ParseSignatureError; + + fn try_from(s: String) -> Result { + Self::from_str(&s) } } impl TryFrom> for Signature { - type Error = Error; + type Error = ParseSignatureError; fn try_from(s: Box) -> Result { - let bytes = Vec::from_hex(&s)?; - let (sighash_byte, signature) = bytes.split_last().ok_or(Error::EmptySignature)?; - Ok(Signature { - signature: secp256k1::ecdsa::Signature::from_der(signature)?, - sighash_type: EcdsaSighashType::from_standard(*sighash_byte as u32)?, - }) + Self::from_str(&s) } } impl TryFrom> for Signature { - type Error = Error; + type Error = ParseSignatureError; fn try_from(s: Arc) -> Result { - let bytes = Vec::from_hex(&s)?; - let (sighash_byte, signature) = bytes.split_last().ok_or(Error::EmptySignature)?; - Ok(Signature { - signature: secp256k1::ecdsa::Signature::from_der(signature)?, - sighash_type: EcdsaSighashType::from_standard(*sighash_byte as u32)?, - }) + Self::from_str(&s) } } impl TryFrom> for Signature { - type Error = Error; + type Error = ParseSignatureError; fn try_from(s: Rc) -> Result { - let bytes = Vec::from_hex(&s)?; - let (sighash_byte, signature) = bytes.split_last().ok_or(Error::EmptySignature)?; - Ok(Signature { - signature: secp256k1::ecdsa::Signature::from_der(signature)?, - sighash_type: EcdsaSighashType::from_standard(*sighash_byte as u32)?, - }) + Self::from_str(&s) } }