Skip to content

Commit 7a417fd

Browse files
committed
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`.
1 parent dc90a43 commit 7a417fd

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/constants.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ pub const COMPACT_SIGNATURE_SIZE: usize = 64;
3838
pub const SCHNORRSIG_SIGNATURE_SIZE: usize = 64;
3939

4040
/// The size of a Schnorr public key.
41-
pub const SCHNORRSIG_PUBLIC_KEY_SIZE: usize = 32;
41+
pub const SCHNORR_PUBLIC_KEY_SIZE: usize = 32;
42+
43+
/// The size of a Schnorr public key.
44+
#[deprecated(since = "0.22.0", note = "Use SCHNORR_PUBLIC_KEY_SIZE instead.")]
45+
pub const SCHNORRSIG_PUBLIC_KEY_SIZE: usize = SCHNORR_PUBLIC_KEY_SIZE;
4246

4347
/// The size of a key pair.
4448
pub const KEY_PAIR_SIZE: usize = 96;

src/key.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -991,10 +991,10 @@ impl fmt::Display for XOnlyPublicKey {
991991
impl str::FromStr for XOnlyPublicKey {
992992
type Err = Error;
993993
fn from_str(s: &str) -> Result<XOnlyPublicKey, Error> {
994-
let mut res = [0u8; constants::SCHNORRSIG_PUBLIC_KEY_SIZE];
994+
let mut res = [0u8; constants::SCHNORR_PUBLIC_KEY_SIZE];
995995
match from_hex(s, &mut res) {
996-
Ok(constants::SCHNORRSIG_PUBLIC_KEY_SIZE) => {
997-
XOnlyPublicKey::from_slice(&res[0..constants::SCHNORRSIG_PUBLIC_KEY_SIZE])
996+
Ok(constants::SCHNORR_PUBLIC_KEY_SIZE) => {
997+
XOnlyPublicKey::from_slice(&res[0..constants::SCHNORR_PUBLIC_KEY_SIZE])
998998
}
999999
_ => Err(Error::InvalidPublicKey),
10001000
}
@@ -1039,7 +1039,7 @@ impl XOnlyPublicKey {
10391039
/// slice does not represent a valid Secp256k1 point x coordinate.
10401040
#[inline]
10411041
pub fn from_slice(data: &[u8]) -> Result<XOnlyPublicKey, Error> {
1042-
if data.is_empty() || data.len() != constants::SCHNORRSIG_PUBLIC_KEY_SIZE {
1042+
if data.is_empty() || data.len() != constants::SCHNORR_PUBLIC_KEY_SIZE {
10431043
return Err(Error::InvalidPublicKey);
10441044
}
10451045

@@ -1060,8 +1060,8 @@ impl XOnlyPublicKey {
10601060

10611061
#[inline]
10621062
/// Serializes the key as a byte-encoded x coordinate value (32 bytes).
1063-
pub fn serialize(&self) -> [u8; constants::SCHNORRSIG_PUBLIC_KEY_SIZE] {
1064-
let mut ret = [0u8; constants::SCHNORRSIG_PUBLIC_KEY_SIZE];
1063+
pub fn serialize(&self) -> [u8; constants::SCHNORR_PUBLIC_KEY_SIZE] {
1064+
let mut ret = [0u8; constants::SCHNORR_PUBLIC_KEY_SIZE];
10651065

10661066
unsafe {
10671067
let err = ffi::secp256k1_xonly_pubkey_serialize(

src/schnorr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,24 +439,24 @@ mod tests {
439439
fn test_pubkey_from_bad_slice() {
440440
// Bad sizes
441441
assert_eq!(
442-
XOnlyPublicKey::from_slice(&[0; constants::SCHNORRSIG_PUBLIC_KEY_SIZE - 1]),
442+
XOnlyPublicKey::from_slice(&[0; constants::SCHNORR_PUBLIC_KEY_SIZE - 1]),
443443
Err(InvalidPublicKey)
444444
);
445445
assert_eq!(
446-
XOnlyPublicKey::from_slice(&[0; constants::SCHNORRSIG_PUBLIC_KEY_SIZE + 1]),
446+
XOnlyPublicKey::from_slice(&[0; constants::SCHNORR_PUBLIC_KEY_SIZE + 1]),
447447
Err(InvalidPublicKey)
448448
);
449449

450450
// Bad parse
451451
assert_eq!(
452-
XOnlyPublicKey::from_slice(&[0xff; constants::SCHNORRSIG_PUBLIC_KEY_SIZE]),
452+
XOnlyPublicKey::from_slice(&[0xff; constants::SCHNORR_PUBLIC_KEY_SIZE]),
453453
Err(InvalidPublicKey)
454454
);
455455
// In fuzzing mode restrictions on public key validity are much more
456456
// relaxed, thus the invalid check below is expected to fail.
457457
#[cfg(not(fuzzing))]
458458
assert_eq!(
459-
XOnlyPublicKey::from_slice(&[0x55; constants::SCHNORRSIG_PUBLIC_KEY_SIZE]),
459+
XOnlyPublicKey::from_slice(&[0x55; constants::SCHNORR_PUBLIC_KEY_SIZE]),
460460
Err(InvalidPublicKey)
461461
);
462462
assert_eq!(XOnlyPublicKey::from_slice(&[]), Err(InvalidPublicKey));

0 commit comments

Comments
 (0)