@@ -219,7 +219,7 @@ impl SecretKey {
219219 /// use secp256k1::SecretKey;
220220 /// let sk = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order");
221221 /// ```
222- #[ deprecated( since = "TBD " , note = "Use `from_byte_array` instead." ) ]
222+ #[ deprecated( since = "0.30.0 " , note = "Use `from_byte_array` instead." ) ]
223223 #[ inline]
224224 pub fn from_slice ( data : & [ u8 ] ) -> Result < SecretKey , Error > {
225225 match <[ u8 ; constants:: SECRET_KEY_SIZE ] >:: try_from ( data) {
@@ -401,10 +401,10 @@ impl<'de> serde::Deserialize<'de> for SecretKey {
401401 "a hex string representing 32 byte SecretKey" ,
402402 ) )
403403 } else {
404- let visitor =
405- super :: serde_util :: Tuple32Visitor :: new ( "raw 32 bytes SecretKey" , |bytes| {
406- SecretKey :: from_byte_array ( bytes )
407- } ) ;
404+ let visitor = super :: serde_util :: Tuple32Visitor :: new (
405+ "raw 32 bytes SecretKey" ,
406+ SecretKey :: from_byte_array,
407+ ) ;
408408 d. deserialize_tuple ( constants:: SECRET_KEY_SIZE , visitor)
409409 }
410410 }
@@ -790,10 +790,10 @@ impl<'de> serde::Deserialize<'de> for PublicKey {
790790 "an ASCII hex string representing a public key" ,
791791 ) )
792792 } else {
793- let visitor =
794- super :: serde_util :: Tuple33Visitor :: new ( "33 bytes compressed public key" , |bytes| {
795- PublicKey :: from_byte_array_compressed ( bytes )
796- } ) ;
793+ let visitor = super :: serde_util :: Tuple33Visitor :: new (
794+ "33 bytes compressed public key" ,
795+ PublicKey :: from_byte_array_compressed,
796+ ) ;
797797 d. deserialize_tuple ( constants:: PUBLIC_KEY_SIZE , visitor)
798798 }
799799 }
@@ -860,7 +860,7 @@ impl Keypair {
860860 ///
861861 /// [`Error::InvalidSecretKey`] if the slice is not exactly 32 bytes long,
862862 /// or if the encoded number is an invalid scalar.
863- #[ deprecated( since = "TBD " , note = "Use `from_seckey_byte_array` instead." ) ]
863+ #[ deprecated( since = "0.31.0 " , note = "Use `from_seckey_byte_array` instead." ) ]
864864 #[ inline]
865865 pub fn from_seckey_slice < C : Signing > (
866866 secp : & Secp256k1 < C > ,
@@ -1239,7 +1239,7 @@ impl XOnlyPublicKey {
12391239 ///
12401240 /// Returns [`Error::InvalidPublicKey`] if the length of the data slice is not 32 bytes or the
12411241 /// slice does not represent a valid Secp256k1 point x coordinate.
1242- #[ deprecated( since = "TBD " , note = "Use `from_byte_array` instead." ) ]
1242+ #[ deprecated( since = "0.30.0 " , note = "Use `from_byte_array` instead." ) ]
12431243 #[ inline]
12441244 pub fn from_slice ( data : & [ u8 ] ) -> Result < XOnlyPublicKey , Error > {
12451245 match <[ u8 ; constants:: SCHNORR_PUBLIC_KEY_SIZE ] >:: try_from ( data) {
@@ -1634,6 +1634,7 @@ mod test {
16341634 use crate :: { constants, from_hex, to_hex, Scalar } ;
16351635
16361636 #[ test]
1637+ #[ allow( deprecated) ]
16371638 fn skey_from_slice ( ) {
16381639 let sk = SecretKey :: from_slice ( & [ 1 ; 31 ] ) ;
16391640 assert_eq ! ( sk, Err ( InvalidSecretKey ) ) ;
@@ -1668,7 +1669,7 @@ mod test {
16681669 let s = Secp256k1 :: new ( ) ;
16691670
16701671 let ( sk1, pk1) = s. generate_keypair ( & mut rand:: rng ( ) ) ;
1671- assert_eq ! ( SecretKey :: from_slice ( & sk1[ .. ] ) , Ok ( sk1) ) ;
1672+ assert_eq ! ( SecretKey :: from_byte_array ( sk1. secret_bytes ( ) ) , Ok ( sk1) ) ;
16721673 assert_eq ! ( PublicKey :: from_slice( & pk1. serialize( ) [ ..] ) , Ok ( pk1) ) ;
16731674 assert_eq ! ( PublicKey :: from_slice( & pk1. serialize_uncompressed( ) [ ..] ) , Ok ( pk1) ) ;
16741675 }
@@ -1688,22 +1689,22 @@ mod test {
16881689 #[ rustfmt:: skip]
16891690 fn invalid_secret_key ( ) {
16901691 // Zero
1691- assert_eq ! ( SecretKey :: from_slice ( & [ 0 ; 32 ] ) , Err ( InvalidSecretKey ) ) ;
1692+ assert_eq ! ( SecretKey :: from_byte_array ( [ 0 ; 32 ] ) , Err ( InvalidSecretKey ) ) ;
16921693 assert_eq ! (
16931694 SecretKey :: from_str( "0000000000000000000000000000000000000000000000000000000000000000" ) ,
16941695 Err ( InvalidSecretKey )
16951696 ) ;
16961697 // -1
1697- assert_eq ! ( SecretKey :: from_slice ( & [ 0xff ; 32 ] ) , Err ( InvalidSecretKey ) ) ;
1698+ assert_eq ! ( SecretKey :: from_byte_array ( [ 0xff ; 32 ] ) , Err ( InvalidSecretKey ) ) ;
16981699 // Top of range
1699- assert ! ( SecretKey :: from_slice ( & [
1700+ assert ! ( SecretKey :: from_byte_array ( [
17001701 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF ,
17011702 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFE ,
17021703 0xBA , 0xAE , 0xDC , 0xE6 , 0xAF , 0x48 , 0xA0 , 0x3B ,
17031704 0xBF , 0xD2 , 0x5E , 0x8C , 0xD0 , 0x36 , 0x41 , 0x40 ,
17041705 ] ) . is_ok( ) ) ;
17051706 // One past top of range
1706- assert ! ( SecretKey :: from_slice ( & [
1707+ assert ! ( SecretKey :: from_byte_array ( [
17071708 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF ,
17081709 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFE ,
17091710 0xBA , 0xAE , 0xDC , 0xE6 , 0xAF , 0x48 , 0xA0 , 0x3B ,
@@ -1772,6 +1773,7 @@ mod test {
17721773 }
17731774
17741775 #[ test]
1776+ #[ allow( deprecated) ]
17751777 fn test_seckey_from_bad_slice ( ) {
17761778 // Bad sizes
17771779 assert_eq ! (
@@ -1825,7 +1827,7 @@ mod test {
18251827
18261828 #[ cfg( not( secp256k1_fuzz) ) ]
18271829 let s = Secp256k1 :: signing_only ( ) ;
1828- let sk = SecretKey :: from_slice ( & SK_BYTES ) . expect ( "sk" ) ;
1830+ let sk = SecretKey :: from_byte_array ( SK_BYTES ) . expect ( "sk" ) ;
18291831
18301832 // In fuzzing mode secret->public key derivation is different, so
18311833 // hard-code the expected result.
@@ -2180,7 +2182,7 @@ mod test {
21802182
21812183 #[ cfg( not( secp256k1_fuzz) ) ]
21822184 let s = Secp256k1 :: new ( ) ;
2183- let sk = SecretKey :: from_slice ( & SK_BYTES ) . unwrap ( ) ;
2185+ let sk = SecretKey :: from_byte_array ( SK_BYTES ) . unwrap ( ) ;
21842186
21852187 // In fuzzing mode secret->public key derivation is different, so
21862188 // hard-code the expected result.
@@ -2320,10 +2322,11 @@ mod test {
23202322 pk_bytes[ 0 ] = 0x02 ; // Use positive Y co-ordinate.
23212323 pk_bytes[ 1 ..] . clone_from_slice ( & PK_BYTES ) ;
23222324
2323- let sk = SecretKey :: from_slice ( & SK_BYTES ) . expect ( "failed to parse sk bytes" ) ;
2325+ let sk = SecretKey :: from_byte_array ( SK_BYTES ) . expect ( "failed to parse sk bytes" ) ;
23242326 let pk = PublicKey :: from_slice ( & pk_bytes) . expect ( "failed to create pk from iterator" ) ;
23252327 let kp = Keypair :: from_secret_key ( & secp, & sk) ;
2326- let xonly = XOnlyPublicKey :: from_slice ( & PK_BYTES ) . expect ( "failed to get xonly from slice" ) ;
2328+ let xonly =
2329+ XOnlyPublicKey :: from_byte_array ( PK_BYTES ) . expect ( "failed to get xonly from slice" ) ;
23272330
23282331 ( sk, pk, kp, xonly)
23292332 }
0 commit comments