Refactor use map_err
This commit is contained in:
parent
ec90044535
commit
9f848472e4
|
@ -109,16 +109,21 @@ impl Deserialize for EcdsaSig {
|
||||||
// also has a field sighash_u32 (See BIP141). For example, when signing with non-standard
|
// also has a field sighash_u32 (See BIP141). For example, when signing with non-standard
|
||||||
// 0x05, the sighash message would have the last field as 0x05u32 while, the verification
|
// 0x05, the sighash message would have the last field as 0x05u32 while, the verification
|
||||||
// would use check the signature assuming sighash_u32 as `0x01`.
|
// would use check the signature assuming sighash_u32 as `0x01`.
|
||||||
match EcdsaSig::from_slice(&bytes) {
|
EcdsaSig::from_slice(&bytes)
|
||||||
Ok(sig) => Ok(sig),
|
.map_err(|e| match e {
|
||||||
Err(EcdsaSigError::EmptySignature) =>
|
EcdsaSigError::EmptySignature => {
|
||||||
Err(encode::Error::ParseFailed("Empty partial signature data")),
|
encode::Error::ParseFailed("Empty partial signature data")
|
||||||
Err(EcdsaSigError::NonStandardSigHashType(flag)) =>
|
|
||||||
Err(encode::Error::from(psbt::Error::NonStandardSigHashType(flag))),
|
|
||||||
Err(EcdsaSigError::Secp256k1(..)) =>
|
|
||||||
Err(encode::Error::ParseFailed("Invalid Ecdsa signature")),
|
|
||||||
Err(EcdsaSigError::HexEncoding(..)) => unreachable!("Decoding from slice, not hex")
|
|
||||||
}
|
}
|
||||||
|
EcdsaSigError::NonStandardSigHashType(flag) => {
|
||||||
|
encode::Error::from(psbt::Error::NonStandardSigHashType(flag))
|
||||||
|
}
|
||||||
|
EcdsaSigError::Secp256k1(..) => {
|
||||||
|
encode::Error::ParseFailed("Invalid Ecdsa signature")
|
||||||
|
}
|
||||||
|
EcdsaSigError::HexEncoding(..) => {
|
||||||
|
unreachable!("Decoding from slice, not hex")
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,16 +210,18 @@ impl Serialize for schnorr::SchnorrSig {
|
||||||
|
|
||||||
impl Deserialize for schnorr::SchnorrSig {
|
impl Deserialize for schnorr::SchnorrSig {
|
||||||
fn deserialize(bytes: &[u8]) -> Result<Self, encode::Error> {
|
fn deserialize(bytes: &[u8]) -> Result<Self, encode::Error> {
|
||||||
match schnorr::SchnorrSig::from_slice(&bytes) {
|
schnorr::SchnorrSig::from_slice(&bytes)
|
||||||
Ok(sig) => Ok(sig),
|
.map_err(|e| match e {
|
||||||
Err(schnorr::SchnorrSigError::InvalidSighashType(flag)) => {
|
schnorr::SchnorrSigError::InvalidSighashType(flag) => {
|
||||||
Err(encode::Error::from(psbt::Error::NonStandardSigHashType(flag as u32)))
|
encode::Error::from(psbt::Error::NonStandardSigHashType(flag as u32))
|
||||||
}
|
}
|
||||||
Err(schnorr::SchnorrSigError::InvalidSchnorrSigSize(_)) =>
|
schnorr::SchnorrSigError::InvalidSchnorrSigSize(_) => {
|
||||||
Err(encode::Error::ParseFailed("Invalid Schnorr signature length")),
|
encode::Error::ParseFailed("Invalid Schnorr signature length")
|
||||||
Err(schnorr::SchnorrSigError::Secp256k1(..)) =>
|
|
||||||
Err(encode::Error::ParseFailed("Invalid Schnorr signature")),
|
|
||||||
}
|
}
|
||||||
|
schnorr::SchnorrSigError::Secp256k1(..) => {
|
||||||
|
encode::Error::ParseFailed("Invalid Schnorr signature")
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue