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`.
This commit is contained in:
parent
dc90a43e68
commit
7a417fd1c5
|
@ -38,7 +38,11 @@ pub const COMPACT_SIGNATURE_SIZE: usize = 64;
|
||||||
pub const SCHNORRSIG_SIGNATURE_SIZE: usize = 64;
|
pub const SCHNORRSIG_SIGNATURE_SIZE: usize = 64;
|
||||||
|
|
||||||
/// The size of a Schnorr public key.
|
/// 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.
|
/// The size of a key pair.
|
||||||
pub const KEY_PAIR_SIZE: usize = 96;
|
pub const KEY_PAIR_SIZE: usize = 96;
|
||||||
|
|
12
src/key.rs
12
src/key.rs
|
@ -991,10 +991,10 @@ impl fmt::Display for XOnlyPublicKey {
|
||||||
impl str::FromStr for XOnlyPublicKey {
|
impl str::FromStr for XOnlyPublicKey {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
fn from_str(s: &str) -> Result<XOnlyPublicKey, Error> {
|
fn from_str(s: &str) -> Result<XOnlyPublicKey, Error> {
|
||||||
let mut res = [0u8; constants::SCHNORRSIG_PUBLIC_KEY_SIZE];
|
let mut res = [0u8; constants::SCHNORR_PUBLIC_KEY_SIZE];
|
||||||
match from_hex(s, &mut res) {
|
match from_hex(s, &mut res) {
|
||||||
Ok(constants::SCHNORRSIG_PUBLIC_KEY_SIZE) => {
|
Ok(constants::SCHNORR_PUBLIC_KEY_SIZE) => {
|
||||||
XOnlyPublicKey::from_slice(&res[0..constants::SCHNORRSIG_PUBLIC_KEY_SIZE])
|
XOnlyPublicKey::from_slice(&res[0..constants::SCHNORR_PUBLIC_KEY_SIZE])
|
||||||
}
|
}
|
||||||
_ => Err(Error::InvalidPublicKey),
|
_ => Err(Error::InvalidPublicKey),
|
||||||
}
|
}
|
||||||
|
@ -1039,7 +1039,7 @@ impl XOnlyPublicKey {
|
||||||
/// slice does not represent a valid Secp256k1 point x coordinate.
|
/// slice does not represent a valid Secp256k1 point x coordinate.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_slice(data: &[u8]) -> Result<XOnlyPublicKey, Error> {
|
pub fn from_slice(data: &[u8]) -> Result<XOnlyPublicKey, Error> {
|
||||||
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);
|
return Err(Error::InvalidPublicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1060,8 +1060,8 @@ impl XOnlyPublicKey {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Serializes the key as a byte-encoded x coordinate value (32 bytes).
|
/// Serializes the key as a byte-encoded x coordinate value (32 bytes).
|
||||||
pub fn serialize(&self) -> [u8; constants::SCHNORRSIG_PUBLIC_KEY_SIZE] {
|
pub fn serialize(&self) -> [u8; constants::SCHNORR_PUBLIC_KEY_SIZE] {
|
||||||
let mut ret = [0u8; constants::SCHNORRSIG_PUBLIC_KEY_SIZE];
|
let mut ret = [0u8; constants::SCHNORR_PUBLIC_KEY_SIZE];
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let err = ffi::secp256k1_xonly_pubkey_serialize(
|
let err = ffi::secp256k1_xonly_pubkey_serialize(
|
||||||
|
|
|
@ -439,24 +439,24 @@ mod tests {
|
||||||
fn test_pubkey_from_bad_slice() {
|
fn test_pubkey_from_bad_slice() {
|
||||||
// Bad sizes
|
// Bad sizes
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
XOnlyPublicKey::from_slice(&[0; constants::SCHNORRSIG_PUBLIC_KEY_SIZE - 1]),
|
XOnlyPublicKey::from_slice(&[0; constants::SCHNORR_PUBLIC_KEY_SIZE - 1]),
|
||||||
Err(InvalidPublicKey)
|
Err(InvalidPublicKey)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
XOnlyPublicKey::from_slice(&[0; constants::SCHNORRSIG_PUBLIC_KEY_SIZE + 1]),
|
XOnlyPublicKey::from_slice(&[0; constants::SCHNORR_PUBLIC_KEY_SIZE + 1]),
|
||||||
Err(InvalidPublicKey)
|
Err(InvalidPublicKey)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Bad parse
|
// Bad parse
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
XOnlyPublicKey::from_slice(&[0xff; constants::SCHNORRSIG_PUBLIC_KEY_SIZE]),
|
XOnlyPublicKey::from_slice(&[0xff; constants::SCHNORR_PUBLIC_KEY_SIZE]),
|
||||||
Err(InvalidPublicKey)
|
Err(InvalidPublicKey)
|
||||||
);
|
);
|
||||||
// In fuzzing mode restrictions on public key validity are much more
|
// In fuzzing mode restrictions on public key validity are much more
|
||||||
// relaxed, thus the invalid check below is expected to fail.
|
// relaxed, thus the invalid check below is expected to fail.
|
||||||
#[cfg(not(fuzzing))]
|
#[cfg(not(fuzzing))]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
XOnlyPublicKey::from_slice(&[0x55; constants::SCHNORRSIG_PUBLIC_KEY_SIZE]),
|
XOnlyPublicKey::from_slice(&[0x55; constants::SCHNORR_PUBLIC_KEY_SIZE]),
|
||||||
Err(InvalidPublicKey)
|
Err(InvalidPublicKey)
|
||||||
);
|
);
|
||||||
assert_eq!(XOnlyPublicKey::from_slice(&[]), Err(InvalidPublicKey));
|
assert_eq!(XOnlyPublicKey::from_slice(&[]), Err(InvalidPublicKey));
|
||||||
|
|
Loading…
Reference in New Issue