@@ -220,7 +220,7 @@ impl SecretKey {
220
220
/// use secp256k1::SecretKey;
221
221
/// let sk = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order");
222
222
/// ```
223
- #[ deprecated( since = "TBD " , note = "Use `from_byte_array` instead." ) ]
223
+ #[ deprecated( since = "0.31.0 " , note = "Use `from_byte_array` instead." ) ]
224
224
#[ inline]
225
225
pub fn from_slice ( data : & [ u8 ] ) -> Result < SecretKey , Error > {
226
226
match <[ u8 ; constants:: SECRET_KEY_SIZE ] >:: try_from ( data) {
@@ -402,10 +402,10 @@ impl<'de> serde::Deserialize<'de> for SecretKey {
402
402
"a hex string representing 32 byte SecretKey" ,
403
403
) )
404
404
} else {
405
- let visitor =
406
- super :: serde_util :: Tuple32Visitor :: new ( "raw 32 bytes SecretKey" , |bytes| {
407
- SecretKey :: from_byte_array ( bytes )
408
- } ) ;
405
+ let visitor = super :: serde_util :: Tuple32Visitor :: new (
406
+ "raw 32 bytes SecretKey" ,
407
+ SecretKey :: from_byte_array,
408
+ ) ;
409
409
d. deserialize_tuple ( constants:: SECRET_KEY_SIZE , visitor)
410
410
}
411
411
}
@@ -791,10 +791,10 @@ impl<'de> serde::Deserialize<'de> for PublicKey {
791
791
"an ASCII hex string representing a public key" ,
792
792
) )
793
793
} else {
794
- let visitor =
795
- super :: serde_util :: Tuple33Visitor :: new ( "33 bytes compressed public key" , |bytes| {
796
- PublicKey :: from_byte_array_compressed ( bytes )
797
- } ) ;
794
+ let visitor = super :: serde_util :: Tuple33Visitor :: new (
795
+ "33 bytes compressed public key" ,
796
+ PublicKey :: from_byte_array_compressed,
797
+ ) ;
798
798
d. deserialize_tuple ( constants:: PUBLIC_KEY_SIZE , visitor)
799
799
}
800
800
}
@@ -861,7 +861,7 @@ impl Keypair {
861
861
///
862
862
/// [`Error::InvalidSecretKey`] if the slice is not exactly 32 bytes long,
863
863
/// or if the encoded number is an invalid scalar.
864
- #[ deprecated( since = "TBD " , note = "Use `from_seckey_byte_array` instead." ) ]
864
+ #[ deprecated( since = "0.31.0 " , note = "Use `from_seckey_byte_array` instead." ) ]
865
865
#[ inline]
866
866
pub fn from_seckey_slice < C : Signing > (
867
867
secp : & Secp256k1 < C > ,
@@ -1240,7 +1240,7 @@ impl XOnlyPublicKey {
1240
1240
///
1241
1241
/// Returns [`Error::InvalidPublicKey`] if the length of the data slice is not 32 bytes or the
1242
1242
/// slice does not represent a valid Secp256k1 point x coordinate.
1243
- #[ deprecated( since = "TBD " , note = "Use `from_byte_array` instead." ) ]
1243
+ #[ deprecated( since = "0.31.0 " , note = "Use `from_byte_array` instead." ) ]
1244
1244
#[ inline]
1245
1245
pub fn from_slice ( data : & [ u8 ] ) -> Result < XOnlyPublicKey , Error > {
1246
1246
match <[ u8 ; constants:: SCHNORR_PUBLIC_KEY_SIZE ] >:: try_from ( data) {
@@ -1673,6 +1673,7 @@ mod test {
1673
1673
use crate :: { constants, from_hex, to_hex, Scalar } ;
1674
1674
1675
1675
#[ test]
1676
+ #[ allow( deprecated) ]
1676
1677
fn skey_from_slice ( ) {
1677
1678
let sk = SecretKey :: from_slice ( & [ 1 ; 31 ] ) ;
1678
1679
assert_eq ! ( sk, Err ( InvalidSecretKey ) ) ;
@@ -1707,7 +1708,7 @@ mod test {
1707
1708
let s = Secp256k1 :: new ( ) ;
1708
1709
1709
1710
let ( sk1, pk1) = s. generate_keypair ( & mut rand:: rng ( ) ) ;
1710
- assert_eq ! ( SecretKey :: from_slice ( & sk1[ .. ] ) , Ok ( sk1) ) ;
1711
+ assert_eq ! ( SecretKey :: from_byte_array ( sk1. secret_bytes ( ) ) , Ok ( sk1) ) ;
1711
1712
assert_eq ! ( PublicKey :: from_slice( & pk1. serialize( ) [ ..] ) , Ok ( pk1) ) ;
1712
1713
assert_eq ! ( PublicKey :: from_slice( & pk1. serialize_uncompressed( ) [ ..] ) , Ok ( pk1) ) ;
1713
1714
}
@@ -1727,22 +1728,22 @@ mod test {
1727
1728
#[ rustfmt:: skip]
1728
1729
fn invalid_secret_key ( ) {
1729
1730
// Zero
1730
- assert_eq ! ( SecretKey :: from_slice ( & [ 0 ; 32 ] ) , Err ( InvalidSecretKey ) ) ;
1731
+ assert_eq ! ( SecretKey :: from_byte_array ( [ 0 ; 32 ] ) , Err ( InvalidSecretKey ) ) ;
1731
1732
assert_eq ! (
1732
1733
SecretKey :: from_str( "0000000000000000000000000000000000000000000000000000000000000000" ) ,
1733
1734
Err ( InvalidSecretKey )
1734
1735
) ;
1735
1736
// -1
1736
- assert_eq ! ( SecretKey :: from_slice ( & [ 0xff ; 32 ] ) , Err ( InvalidSecretKey ) ) ;
1737
+ assert_eq ! ( SecretKey :: from_byte_array ( [ 0xff ; 32 ] ) , Err ( InvalidSecretKey ) ) ;
1737
1738
// Top of range
1738
- assert ! ( SecretKey :: from_slice ( & [
1739
+ assert ! ( SecretKey :: from_byte_array ( [
1739
1740
0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF ,
1740
1741
0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFE ,
1741
1742
0xBA , 0xAE , 0xDC , 0xE6 , 0xAF , 0x48 , 0xA0 , 0x3B ,
1742
1743
0xBF , 0xD2 , 0x5E , 0x8C , 0xD0 , 0x36 , 0x41 , 0x40 ,
1743
1744
] ) . is_ok( ) ) ;
1744
1745
// One past top of range
1745
- assert ! ( SecretKey :: from_slice ( & [
1746
+ assert ! ( SecretKey :: from_byte_array ( [
1746
1747
0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF ,
1747
1748
0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFE ,
1748
1749
0xBA , 0xAE , 0xDC , 0xE6 , 0xAF , 0x48 , 0xA0 , 0x3B ,
@@ -1811,6 +1812,7 @@ mod test {
1811
1812
}
1812
1813
1813
1814
#[ test]
1815
+ #[ allow( deprecated) ]
1814
1816
fn test_seckey_from_bad_slice ( ) {
1815
1817
// Bad sizes
1816
1818
assert_eq ! (
@@ -1864,7 +1866,7 @@ mod test {
1864
1866
1865
1867
#[ cfg( not( secp256k1_fuzz) ) ]
1866
1868
let s = Secp256k1 :: signing_only ( ) ;
1867
- let sk = SecretKey :: from_slice ( & SK_BYTES ) . expect ( "sk" ) ;
1869
+ let sk = SecretKey :: from_byte_array ( SK_BYTES ) . expect ( "sk" ) ;
1868
1870
1869
1871
// In fuzzing mode secret->public key derivation is different, so
1870
1872
// hard-code the expected result.
@@ -2219,7 +2221,7 @@ mod test {
2219
2221
2220
2222
#[ cfg( not( secp256k1_fuzz) ) ]
2221
2223
let s = Secp256k1 :: new ( ) ;
2222
- let sk = SecretKey :: from_slice ( & SK_BYTES ) . unwrap ( ) ;
2224
+ let sk = SecretKey :: from_byte_array ( SK_BYTES ) . unwrap ( ) ;
2223
2225
2224
2226
// In fuzzing mode secret->public key derivation is different, so
2225
2227
// hard-code the expected result.
@@ -2359,10 +2361,11 @@ mod test {
2359
2361
pk_bytes[ 0 ] = 0x02 ; // Use positive Y co-ordinate.
2360
2362
pk_bytes[ 1 ..] . clone_from_slice ( & PK_BYTES ) ;
2361
2363
2362
- let sk = SecretKey :: from_slice ( & SK_BYTES ) . expect ( "failed to parse sk bytes" ) ;
2364
+ let sk = SecretKey :: from_byte_array ( SK_BYTES ) . expect ( "failed to parse sk bytes" ) ;
2363
2365
let pk = PublicKey :: from_slice ( & pk_bytes) . expect ( "failed to create pk from iterator" ) ;
2364
2366
let kp = Keypair :: from_secret_key ( & secp, & sk) ;
2365
- let xonly = XOnlyPublicKey :: from_slice ( & PK_BYTES ) . expect ( "failed to get xonly from slice" ) ;
2367
+ let xonly =
2368
+ XOnlyPublicKey :: from_byte_array ( PK_BYTES ) . expect ( "failed to get xonly from slice" ) ;
2366
2369
2367
2370
( sk, pk, kp, xonly)
2368
2371
}
0 commit comments