@@ -220,7 +220,7 @@ impl SecretKey {
220220 /// use secp256k1::SecretKey;
221221 /// let sk = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order");
222222 /// ```
223- #[ deprecated( since = "TBD " , note = "Use `from_byte_array` instead." ) ]
223+ #[ deprecated( since = "0.31.0 " , note = "Use `from_byte_array` instead." ) ]
224224 #[ inline]
225225 pub fn from_slice ( data : & [ u8 ] ) -> Result < SecretKey , Error > {
226226 match <[ u8 ; constants:: SECRET_KEY_SIZE ] >:: try_from ( data) {
@@ -402,10 +402,10 @@ impl<'de> serde::Deserialize<'de> for SecretKey {
402402 "a hex string representing 32 byte SecretKey" ,
403403 ) )
404404 } 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+ ) ;
409409 d. deserialize_tuple ( constants:: SECRET_KEY_SIZE , visitor)
410410 }
411411 }
@@ -791,10 +791,10 @@ impl<'de> serde::Deserialize<'de> for PublicKey {
791791 "an ASCII hex string representing a public key" ,
792792 ) )
793793 } 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+ ) ;
798798 d. deserialize_tuple ( constants:: PUBLIC_KEY_SIZE , visitor)
799799 }
800800 }
@@ -861,7 +861,7 @@ impl Keypair {
861861 ///
862862 /// [`Error::InvalidSecretKey`] if the slice is not exactly 32 bytes long,
863863 /// 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." ) ]
865865 #[ inline]
866866 pub fn from_seckey_slice < C : Signing > (
867867 secp : & Secp256k1 < C > ,
@@ -1240,7 +1240,7 @@ impl XOnlyPublicKey {
12401240 ///
12411241 /// Returns [`Error::InvalidPublicKey`] if the length of the data slice is not 32 bytes or the
12421242 /// 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." ) ]
12441244 #[ inline]
12451245 pub fn from_slice ( data : & [ u8 ] ) -> Result < XOnlyPublicKey , Error > {
12461246 match <[ u8 ; constants:: SCHNORR_PUBLIC_KEY_SIZE ] >:: try_from ( data) {
@@ -1673,6 +1673,7 @@ mod test {
16731673 use crate :: { constants, from_hex, to_hex, Scalar } ;
16741674
16751675 #[ test]
1676+ #[ allow( deprecated) ]
16761677 fn skey_from_slice ( ) {
16771678 let sk = SecretKey :: from_slice ( & [ 1 ; 31 ] ) ;
16781679 assert_eq ! ( sk, Err ( InvalidSecretKey ) ) ;
@@ -1707,7 +1708,7 @@ mod test {
17071708 let s = Secp256k1 :: new ( ) ;
17081709
17091710 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) ) ;
17111712 assert_eq ! ( PublicKey :: from_slice( & pk1. serialize( ) [ ..] ) , Ok ( pk1) ) ;
17121713 assert_eq ! ( PublicKey :: from_slice( & pk1. serialize_uncompressed( ) [ ..] ) , Ok ( pk1) ) ;
17131714 }
@@ -1727,22 +1728,22 @@ mod test {
17271728 #[ rustfmt:: skip]
17281729 fn invalid_secret_key ( ) {
17291730 // Zero
1730- assert_eq ! ( SecretKey :: from_slice ( & [ 0 ; 32 ] ) , Err ( InvalidSecretKey ) ) ;
1731+ assert_eq ! ( SecretKey :: from_byte_array ( [ 0 ; 32 ] ) , Err ( InvalidSecretKey ) ) ;
17311732 assert_eq ! (
17321733 SecretKey :: from_str( "0000000000000000000000000000000000000000000000000000000000000000" ) ,
17331734 Err ( InvalidSecretKey )
17341735 ) ;
17351736 // -1
1736- assert_eq ! ( SecretKey :: from_slice ( & [ 0xff ; 32 ] ) , Err ( InvalidSecretKey ) ) ;
1737+ assert_eq ! ( SecretKey :: from_byte_array ( [ 0xff ; 32 ] ) , Err ( InvalidSecretKey ) ) ;
17371738 // Top of range
1738- assert ! ( SecretKey :: from_slice ( & [
1739+ assert ! ( SecretKey :: from_byte_array ( [
17391740 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF ,
17401741 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFE ,
17411742 0xBA , 0xAE , 0xDC , 0xE6 , 0xAF , 0x48 , 0xA0 , 0x3B ,
17421743 0xBF , 0xD2 , 0x5E , 0x8C , 0xD0 , 0x36 , 0x41 , 0x40 ,
17431744 ] ) . is_ok( ) ) ;
17441745 // One past top of range
1745- assert ! ( SecretKey :: from_slice ( & [
1746+ assert ! ( SecretKey :: from_byte_array ( [
17461747 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF ,
17471748 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFE ,
17481749 0xBA , 0xAE , 0xDC , 0xE6 , 0xAF , 0x48 , 0xA0 , 0x3B ,
@@ -1811,6 +1812,7 @@ mod test {
18111812 }
18121813
18131814 #[ test]
1815+ #[ allow( deprecated) ]
18141816 fn test_seckey_from_bad_slice ( ) {
18151817 // Bad sizes
18161818 assert_eq ! (
@@ -1864,7 +1866,7 @@ mod test {
18641866
18651867 #[ cfg( not( secp256k1_fuzz) ) ]
18661868 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" ) ;
18681870
18691871 // In fuzzing mode secret->public key derivation is different, so
18701872 // hard-code the expected result.
@@ -2219,7 +2221,7 @@ mod test {
22192221
22202222 #[ cfg( not( secp256k1_fuzz) ) ]
22212223 let s = Secp256k1 :: new ( ) ;
2222- let sk = SecretKey :: from_slice ( & SK_BYTES ) . unwrap ( ) ;
2224+ let sk = SecretKey :: from_byte_array ( SK_BYTES ) . unwrap ( ) ;
22232225
22242226 // In fuzzing mode secret->public key derivation is different, so
22252227 // hard-code the expected result.
@@ -2359,10 +2361,11 @@ mod test {
23592361 pk_bytes[ 0 ] = 0x02 ; // Use positive Y co-ordinate.
23602362 pk_bytes[ 1 ..] . clone_from_slice ( & PK_BYTES ) ;
23612363
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" ) ;
23632365 let pk = PublicKey :: from_slice ( & pk_bytes) . expect ( "failed to create pk from iterator" ) ;
23642366 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" ) ;
23662369
23672370 ( sk, pk, kp, xonly)
23682371 }
0 commit comments