Merge rust-bitcoin/rust-bitcoin#794: Refactor use map_err
9f848472e4
Refactor use map_err (wim-web) Pull request description: issue: https://github.com/rust-bitcoin/rust-bitcoin/issues/793 change to using map_err ACKs for top commit: Kixunil: ACK9f848472e4
apoelstra: ACK9f848472e4
Tree-SHA512: 93dac16463bf84825f764f3ef81833c27722a52f56737d30f14160d070959ad13bbfdf5f3c4871b961ce05fa9f75ed36acbacaa40ff6ba3bbf449b9c9173c0c7
This commit is contained in:
commit
64451a2144
|
@ -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))),
|
EcdsaSigError::NonStandardSigHashType(flag) => {
|
||||||
Err(EcdsaSigError::Secp256k1(..)) =>
|
encode::Error::from(psbt::Error::NonStandardSigHashType(flag))
|
||||||
Err(encode::Error::ParseFailed("Invalid Ecdsa signature")),
|
}
|
||||||
Err(EcdsaSigError::HexEncoding(..)) => unreachable!("Decoding from slice, not hex")
|
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