From 7a417fd1c56c114c2070abd11ec90d0ad46cb0b2 Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Tue, 1 Mar 2022 18:34:49 +0000 Subject: [PATCH] Deprecate SCHNORRSIG_PUBLIC_KEY_SIZE Recently we moved from using the identifier 'schnorrsig' to 'schnorr', we omitted to update the schnorr public key size constant. Deprecate `SCHNORRSIG_PUBLIC_KEY_SIZE` and add `SCHONORR_PUBLIC_KEY_SIZE`. --- src/constants.rs | 6 +++++- src/key.rs | 12 ++++++------ src/schnorr.rs | 8 ++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index 07b9d02..047cb03 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -38,7 +38,11 @@ pub const COMPACT_SIGNATURE_SIZE: usize = 64; pub const SCHNORRSIG_SIGNATURE_SIZE: usize = 64; /// The size of a Schnorr public key. -pub const SCHNORRSIG_PUBLIC_KEY_SIZE: usize = 32; +pub const SCHNORR_PUBLIC_KEY_SIZE: usize = 32; + +/// The size of a Schnorr public key. +#[deprecated(since = "0.22.0", note = "Use SCHNORR_PUBLIC_KEY_SIZE instead.")] +pub const SCHNORRSIG_PUBLIC_KEY_SIZE: usize = SCHNORR_PUBLIC_KEY_SIZE; /// The size of a key pair. pub const KEY_PAIR_SIZE: usize = 96; diff --git a/src/key.rs b/src/key.rs index abca805..82ffef9 100644 --- a/src/key.rs +++ b/src/key.rs @@ -991,10 +991,10 @@ impl fmt::Display for XOnlyPublicKey { impl str::FromStr for XOnlyPublicKey { type Err = Error; fn from_str(s: &str) -> Result { - let mut res = [0u8; constants::SCHNORRSIG_PUBLIC_KEY_SIZE]; + let mut res = [0u8; constants::SCHNORR_PUBLIC_KEY_SIZE]; match from_hex(s, &mut res) { - Ok(constants::SCHNORRSIG_PUBLIC_KEY_SIZE) => { - XOnlyPublicKey::from_slice(&res[0..constants::SCHNORRSIG_PUBLIC_KEY_SIZE]) + Ok(constants::SCHNORR_PUBLIC_KEY_SIZE) => { + XOnlyPublicKey::from_slice(&res[0..constants::SCHNORR_PUBLIC_KEY_SIZE]) } _ => Err(Error::InvalidPublicKey), } @@ -1039,7 +1039,7 @@ impl XOnlyPublicKey { /// slice does not represent a valid Secp256k1 point x coordinate. #[inline] pub fn from_slice(data: &[u8]) -> Result { - if data.is_empty() || data.len() != constants::SCHNORRSIG_PUBLIC_KEY_SIZE { + if data.is_empty() || data.len() != constants::SCHNORR_PUBLIC_KEY_SIZE { return Err(Error::InvalidPublicKey); } @@ -1060,8 +1060,8 @@ impl XOnlyPublicKey { #[inline] /// Serializes the key as a byte-encoded x coordinate value (32 bytes). - pub fn serialize(&self) -> [u8; constants::SCHNORRSIG_PUBLIC_KEY_SIZE] { - let mut ret = [0u8; constants::SCHNORRSIG_PUBLIC_KEY_SIZE]; + pub fn serialize(&self) -> [u8; constants::SCHNORR_PUBLIC_KEY_SIZE] { + let mut ret = [0u8; constants::SCHNORR_PUBLIC_KEY_SIZE]; unsafe { let err = ffi::secp256k1_xonly_pubkey_serialize( diff --git a/src/schnorr.rs b/src/schnorr.rs index a66b71e..9906b35 100644 --- a/src/schnorr.rs +++ b/src/schnorr.rs @@ -439,24 +439,24 @@ mod tests { fn test_pubkey_from_bad_slice() { // Bad sizes assert_eq!( - XOnlyPublicKey::from_slice(&[0; constants::SCHNORRSIG_PUBLIC_KEY_SIZE - 1]), + XOnlyPublicKey::from_slice(&[0; constants::SCHNORR_PUBLIC_KEY_SIZE - 1]), Err(InvalidPublicKey) ); assert_eq!( - XOnlyPublicKey::from_slice(&[0; constants::SCHNORRSIG_PUBLIC_KEY_SIZE + 1]), + XOnlyPublicKey::from_slice(&[0; constants::SCHNORR_PUBLIC_KEY_SIZE + 1]), Err(InvalidPublicKey) ); // Bad parse assert_eq!( - XOnlyPublicKey::from_slice(&[0xff; constants::SCHNORRSIG_PUBLIC_KEY_SIZE]), + XOnlyPublicKey::from_slice(&[0xff; constants::SCHNORR_PUBLIC_KEY_SIZE]), Err(InvalidPublicKey) ); // In fuzzing mode restrictions on public key validity are much more // relaxed, thus the invalid check below is expected to fail. #[cfg(not(fuzzing))] assert_eq!( - XOnlyPublicKey::from_slice(&[0x55; constants::SCHNORRSIG_PUBLIC_KEY_SIZE]), + XOnlyPublicKey::from_slice(&[0x55; constants::SCHNORR_PUBLIC_KEY_SIZE]), Err(InvalidPublicKey) ); assert_eq!(XOnlyPublicKey::from_slice(&[]), Err(InvalidPublicKey));