From ea027ce258ca9b7078b1808f66221417a52ff82d Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Wed, 9 Dec 2020 16:49:48 +0000 Subject: [PATCH] schnorrsig: change tweak_add_check to return a bool, take a fixed-length array --- src/schnorrsig.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/schnorrsig.rs b/src/schnorrsig.rs index e9324f5..858a1d5 100644 --- a/src/schnorrsig.rs +++ b/src/schnorrsig.rs @@ -322,12 +322,8 @@ impl PublicKey { secp: &Secp256k1, tweaked_key: &Self, tweaked_parity: bool, - tweak: &[u8], - ) -> Result<(), Error> { - if tweak.len() != 32 { - return Err(Error::InvalidTweak); - } - + tweak: [u8; 32], + ) -> bool { let tweaked_ser = tweaked_key.serialize(); unsafe { let err = ffi::secp256k1_xonly_pubkey_tweak_add_check( @@ -338,11 +334,7 @@ impl PublicKey { tweak.as_c_ptr(), ); - if err == 1 { - Ok(()) - } else { - Err(Error::TweakCheckFailed) - } + err == 1 } } } @@ -766,7 +758,7 @@ mod tests { kp.tweak_add_assign(&s, &tweak).expect("Tweak error"); let parity = pk.tweak_add_assign(&s, &tweak).expect("Tweak error"); assert_eq!(PublicKey::from_keypair(&s, &kp), pk); - orig_pk.tweak_add_check(&s, &pk, parity, &tweak).expect("tweak check"); + assert!(orig_pk.tweak_add_check(&s, &pk, parity, tweak)); } }