Skip to content

Commit 96430df

Browse files
committed
Merge #411: Deprecate schnorrsig
7b91f9d Remove schnorrsig from test names (Tobin Harding) 4b840ff Remove schnorrsig from helper method (Tobin Harding) 79770e1 Deprecate SCHNORRSIG_SIGNATURE_SIZE (Tobin Harding) 7a417fd Deprecate SCHNORRSIG_PUBLIC_KEY_SIZE (Tobin Harding) Pull request description: Recently we moved from using the identifier 'schnorrsig' to 'schnorr' but we missed a few places. Change identifiers to use 'schnorr' instead of 'schnorrsig', deprecate if necessary. Please note, does not touch `secp256k1-sys`. Use of 'schnorrsig' remains in `secp256k1-sys`, ACKs for top commit: apoelstra: ACK 7b91f9d Tree-SHA512: 709594f444b778b521e653822241b41df370a8cb1da802844d19ce12d01edb84bd69453df8bc57ba757b5b8d15cc71b04d787093403d04a436debeaa477f139c
2 parents dc90a43 + 7b91f9d commit 96430df

File tree

3 files changed

+44
-36
lines changed

3 files changed

+44
-36
lines changed

src/constants.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,18 @@ pub const MAX_SIGNATURE_SIZE: usize = 72;
3535
pub const COMPACT_SIGNATURE_SIZE: usize = 64;
3636

3737
/// The size of a Schnorr signature.
38-
pub const SCHNORRSIG_SIGNATURE_SIZE: usize = 64;
38+
pub const SCHNORR_SIGNATURE_SIZE: usize = 64;
39+
40+
/// The size of a Schnorr signature.
41+
#[deprecated(since = "0.22.0", note = "Use SCHNORR_SIGNATURE_SIZE instead.")]
42+
pub const SCHNORRSIG_SIGNATURE_SIZE: usize = SCHNORR_SIGNATURE_SIZE;
43+
44+
/// The size of a Schnorr public key.
45+
pub const SCHNORR_PUBLIC_KEY_SIZE: usize = 32;
3946

4047
/// The size of a Schnorr public key.
41-
pub const SCHNORRSIG_PUBLIC_KEY_SIZE: usize = 32;
48+
#[deprecated(since = "0.22.0", note = "Use SCHNORR_PUBLIC_KEY_SIZE instead.")]
49+
pub const SCHNORRSIG_PUBLIC_KEY_SIZE: usize = SCHNORR_PUBLIC_KEY_SIZE;
4250

4351
/// The size of a key pair.
4452
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: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use {Message, Signing, Verification, KeyPair, XOnlyPublicKey};
1717
use SECP256K1;
1818

1919
/// Represents a Schnorr signature.
20-
pub struct Signature([u8; constants::SCHNORRSIG_SIGNATURE_SIZE]);
21-
impl_array_newtype!(Signature, u8, constants::SCHNORRSIG_SIGNATURE_SIZE);
20+
pub struct Signature([u8; constants::SCHNORR_SIGNATURE_SIZE]);
21+
impl_array_newtype!(Signature, u8, constants::SCHNORR_SIGNATURE_SIZE);
2222
impl_pretty_debug!(Signature);
2323

2424
#[cfg(feature = "serde")]
@@ -68,10 +68,10 @@ impl fmt::Display for Signature {
6868
impl str::FromStr for Signature {
6969
type Err = Error;
7070
fn from_str(s: &str) -> Result<Signature, Error> {
71-
let mut res = [0u8; constants::SCHNORRSIG_SIGNATURE_SIZE];
71+
let mut res = [0u8; constants::SCHNORR_SIGNATURE_SIZE];
7272
match from_hex(s, &mut res) {
73-
Ok(constants::SCHNORRSIG_SIGNATURE_SIZE) => {
74-
Signature::from_slice(&res[0..constants::SCHNORRSIG_SIGNATURE_SIZE])
73+
Ok(constants::SCHNORR_SIGNATURE_SIZE) => {
74+
Signature::from_slice(&res[0..constants::SCHNORR_SIGNATURE_SIZE])
7575
}
7676
_ => Err(Error::InvalidSignature),
7777
}
@@ -83,8 +83,8 @@ impl Signature {
8383
#[inline]
8484
pub fn from_slice(data: &[u8]) -> Result<Signature, Error> {
8585
match data.len() {
86-
constants::SCHNORRSIG_SIGNATURE_SIZE => {
87-
let mut ret = [0u8; constants::SCHNORRSIG_SIGNATURE_SIZE];
86+
constants::SCHNORR_SIGNATURE_SIZE => {
87+
let mut ret = [0u8; constants::SCHNORR_SIGNATURE_SIZE];
8888
ret[..].copy_from_slice(data);
8989
Ok(Signature(ret))
9090
}
@@ -102,14 +102,14 @@ impl Signature {
102102
}
103103

104104
impl<C: Signing> Secp256k1<C> {
105-
fn schnorrsig_sign_helper(
105+
fn sign_schnorr_helper(
106106
&self,
107107
msg: &Message,
108108
keypair: &KeyPair,
109109
nonce_data: *const ffi::types::c_void,
110110
) -> Signature {
111111
unsafe {
112-
let mut sig = [0u8; constants::SCHNORRSIG_SIGNATURE_SIZE];
112+
let mut sig = [0u8; constants::SCHNORR_SIGNATURE_SIZE];
113113
assert_eq!(
114114
1,
115115
ffi::secp256k1_schnorrsig_sign(
@@ -160,7 +160,7 @@ impl<C: Signing> Secp256k1<C> {
160160
msg: &Message,
161161
keypair: &KeyPair,
162162
) -> Signature {
163-
self.schnorrsig_sign_helper(msg, keypair, ptr::null())
163+
self.sign_schnorr_helper(msg, keypair, ptr::null())
164164
}
165165

166166
/// Create a Schnorr signature using the given auxiliary random data.
@@ -181,7 +181,7 @@ impl<C: Signing> Secp256k1<C> {
181181
keypair: &KeyPair,
182182
aux_rand: &[u8; 32],
183183
) -> Signature {
184-
self.schnorrsig_sign_helper(
184+
self.sign_schnorr_helper(
185185
msg,
186186
keypair,
187187
aux_rand.as_c_ptr() as *const ffi::types::c_void,
@@ -214,7 +214,7 @@ impl<C: Signing> Secp256k1<C> {
214214
) -> Signature {
215215
let mut aux = [0u8; 32];
216216
rng.fill_bytes(&mut aux);
217-
self.schnorrsig_sign_helper(msg, keypair, aux.as_c_ptr() as *const ffi::types::c_void)
217+
self.sign_schnorr_helper(msg, keypair, aux.as_c_ptr() as *const ffi::types::c_void)
218218
}
219219
}
220220

@@ -304,8 +304,8 @@ mod tests {
304304

305305
#[test]
306306
#[cfg(all(feature = "std", feature = "rand-std"))]
307-
fn test_schnorrsig_sign_with_aux_rand_verify() {
308-
test_schnorrsig_sign_helper(|secp, msg, seckey, rng| {
307+
fn schnorr_sign_with_aux_rand_verify() {
308+
sign_helper(|secp, msg, seckey, rng| {
309309
let mut aux_rand = [0u8; 32];
310310
rng.fill_bytes(&mut aux_rand);
311311
secp.sign_schnorr_with_aux_rand(msg, seckey, &aux_rand)
@@ -314,30 +314,30 @@ mod tests {
314314

315315
#[test]
316316
#[cfg(all(feature = "std", feature = "rand-std"))]
317-
fn test_schnorrsig_sign_with_rng_verify() {
318-
test_schnorrsig_sign_helper(|secp, msg, seckey, mut rng| {
317+
fn schnor_sign_with_rng_verify() {
318+
sign_helper(|secp, msg, seckey, mut rng| {
319319
secp.sign_schnorr_with_rng(msg, seckey, &mut rng)
320320
})
321321
}
322322

323323
#[test]
324324
#[cfg(all(feature = "std", feature = "rand-std"))]
325-
fn test_schnorrsig_sign_verify() {
326-
test_schnorrsig_sign_helper(|secp, msg, seckey, _| {
325+
fn schnorr_sign_verify() {
326+
sign_helper(|secp, msg, seckey, _| {
327327
secp.sign_schnorr(msg, seckey)
328328
})
329329
}
330330

331331
#[test]
332332
#[cfg(all(feature = "std", feature = "rand-std"))]
333-
fn test_schnorrsig_sign_no_aux_rand_verify() {
334-
test_schnorrsig_sign_helper(|secp, msg, seckey, _| {
333+
fn schnorr_sign_no_aux_rand_verify() {
334+
sign_helper(|secp, msg, seckey, _| {
335335
secp.sign_schnorr_no_aux_rand(msg, seckey)
336336
})
337337
}
338338

339339
#[cfg(all(feature = "std", feature = "rand-std"))]
340-
fn test_schnorrsig_sign_helper(
340+
fn sign_helper(
341341
sign: fn(&Secp256k1<All>, &Message, &KeyPair, &mut ThreadRng) -> Signature,
342342
) {
343343
let secp = Secp256k1::new();
@@ -361,7 +361,7 @@ mod tests {
361361
#[test]
362362
#[cfg(any(feature = "alloc", feature = "std"))]
363363
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
364-
fn test_schnorrsig_sign() {
364+
fn schnorr_sign() {
365365
let secp = Secp256k1::new();
366366

367367
let hex_msg = hex_32!("E48441762FB75010B2AA31A512B62B4148AA3FB08EB0765D76B252559064A614");
@@ -384,7 +384,7 @@ mod tests {
384384
#[test]
385385
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
386386
#[cfg(any(feature = "alloc", feature = "std"))]
387-
fn test_schnorrsig_verify() {
387+
fn schnorr_verify() {
388388
let secp = Secp256k1::new();
389389

390390
let hex_msg = hex_32!("E48441762FB75010B2AA31A512B62B4148AA3FB08EB0765D76B252559064A614");
@@ -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));
@@ -567,7 +567,7 @@ mod tests {
567567
let aux = [3u8; 32];
568568
let sig = s
569569
.sign_schnorr_with_aux_rand(&msg, &keypair, &aux);
570-
static SIG_BYTES: [u8; constants::SCHNORRSIG_SIGNATURE_SIZE] = [
570+
static SIG_BYTES: [u8; constants::SCHNORR_SIGNATURE_SIZE] = [
571571
0x14, 0xd0, 0xbf, 0x1a, 0x89, 0x53, 0x50, 0x6f, 0xb4, 0x60, 0xf5, 0x8b, 0xe1, 0x41,
572572
0xaf, 0x76, 0x7f, 0xd1, 0x12, 0x53, 0x5f, 0xb3, 0x92, 0x2e, 0xf2, 0x17, 0x30, 0x8e,
573573
0x2c, 0x26, 0x70, 0x6f, 0x1e, 0xeb, 0x43, 0x2b, 0x3d, 0xba, 0x9a, 0x01, 0x08, 0x2f,

0 commit comments

Comments
 (0)