Merge rust-bitcoin/rust-bitcoin#1031: refactor: remove SchnorrSignatureHash::Reserved variant

69707b0ccd refactor: remove SchnorrSignatureHash::Reserved variant (eunoia_1729)

Pull request description:

  Resolves #1030

ACKs for top commit:
  sanket1729:
    utACK 69707b0ccd. For reference to other reviewers:
  tcharding:
    ACK 69707b0ccd
  apoelstra:
    ACK 69707b0ccd

Tree-SHA512: d5afe9217e15db8dfd7d712e2fa69d22acda0f93fd7efbc80cf9459303a135a69c8ddf43842584769accb8cffba722ec202dc51f100e0f50262b2561a2fb1699
This commit is contained in:
Andrew Poelstra 2022-06-01 23:26:30 +00:00
commit 09b4198b16
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 1 additions and 24 deletions

View File

@ -162,7 +162,7 @@ pub struct PsbtSighashType {
impl fmt::Display for PsbtSighashType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.schnorr_hash_ty() {
Ok(SchnorrSighashType::Reserved) | Err(_) => write!(f, "{:#x}", self.inner),
Err(_) => write!(f, "{:#x}", self.inner),
Ok(schnorr_hash_ty) => fmt::Display::fmt(&schnorr_hash_ty, f),
}
}
@ -179,7 +179,6 @@ impl FromStr for PsbtSighashType {
// inputs. We also do not support SIGHASH_RESERVED in verbatim form
// ("0xFF" string should be used instead).
match SchnorrSighashType::from_str(s) {
Ok(SchnorrSighashType::Reserved) => return Err(SighashTypeParseError{ unrecognized: s.to_owned() }),
Ok(ty) => return Ok(ty.into()),
Err(_) => {}
}
@ -579,20 +578,6 @@ mod test {
}
}
#[test]
fn psbt_sighash_type_schnorr_notstd() {
for (schnorr, schnorr_str) in &[
(SchnorrSighashType::Reserved, "0xff"),
] {
let sighash = PsbtSighashType::from(*schnorr);
let s = format!("{}", sighash);
assert_eq!(&s, schnorr_str);
let back = PsbtSighashType::from_str(&s).unwrap();
assert_eq!(back, sighash);
assert_eq!(back.schnorr_hash_ty().unwrap(), *schnorr);
}
}
#[test]
fn psbt_sighash_type_notstd() {
let nonstd = 0xdddddddd;

View File

@ -125,9 +125,6 @@ pub enum SchnorrSighashType {
NonePlusAnyoneCanPay = 0x82,
/// 0x83: Sign one output and only this input (see `Single` for what "one output" means).
SinglePlusAnyoneCanPay = 0x83,
/// Reserved for future use, `#[non_exhaustive]` is not available with MSRV 1.29.0
Reserved = 0xFF,
}
serde_string_impl!(SchnorrSighashType, "a SchnorrSighashType data");
@ -141,7 +138,6 @@ impl fmt::Display for SchnorrSighashType {
SchnorrSighashType::AllPlusAnyoneCanPay => "SIGHASH_ALL|SIGHASH_ANYONECANPAY",
SchnorrSighashType::NonePlusAnyoneCanPay => "SIGHASH_NONE|SIGHASH_ANYONECANPAY",
SchnorrSighashType::SinglePlusAnyoneCanPay => "SIGHASH_SINGLE|SIGHASH_ANYONECANPAY",
SchnorrSighashType::Reserved => "SIGHASH_RESERVED",
};
f.write_str(s)
}
@ -159,7 +155,6 @@ impl str::FromStr for SchnorrSighashType {
"SIGHASH_ALL|SIGHASH_ANYONECANPAY" => Ok(SchnorrSighashType::AllPlusAnyoneCanPay),
"SIGHASH_NONE|SIGHASH_ANYONECANPAY" => Ok(SchnorrSighashType::NonePlusAnyoneCanPay),
"SIGHASH_SINGLE|SIGHASH_ANYONECANPAY" => Ok(SchnorrSighashType::SinglePlusAnyoneCanPay),
"SIGHASH_RESERVED" => Ok(SchnorrSighashType::Reserved),
_ => Err(SighashTypeParseError{ unrecognized: s.to_owned() }),
}
}
@ -330,7 +325,6 @@ impl SchnorrSighashType {
SchnorrSighashType::AllPlusAnyoneCanPay => (SchnorrSighashType::All, true),
SchnorrSighashType::NonePlusAnyoneCanPay => (SchnorrSighashType::None, true),
SchnorrSighashType::SinglePlusAnyoneCanPay => (SchnorrSighashType::Single, true),
SchnorrSighashType::Reserved => (SchnorrSighashType::Reserved, false),
}
}
@ -344,7 +338,6 @@ impl SchnorrSighashType {
0x81 => Ok(SchnorrSighashType::AllPlusAnyoneCanPay),
0x82 => Ok(SchnorrSighashType::NonePlusAnyoneCanPay),
0x83 => Ok(SchnorrSighashType::SinglePlusAnyoneCanPay),
0xFF => Ok(SchnorrSighashType::Reserved),
x => Err(Error::InvalidSighashType(x as u32)),
}
}
@ -1174,7 +1167,6 @@ mod tests {
("SIGHASH_ALL|SIGHASH_ANYONECANPAY", SchnorrSighashType::AllPlusAnyoneCanPay),
("SIGHASH_NONE|SIGHASH_ANYONECANPAY", SchnorrSighashType::NonePlusAnyoneCanPay),
("SIGHASH_SINGLE|SIGHASH_ANYONECANPAY", SchnorrSighashType::SinglePlusAnyoneCanPay),
("SIGHASH_RESERVED", SchnorrSighashType::Reserved),
];
for (s, sht) in sighashtypes {
assert_eq!(sht.to_string(), s);