@@ -115,7 +115,7 @@ impl str::FromStr for SecretKey {
115115 fn from_str ( s : & str ) -> Result < SecretKey , Error > {
116116 let mut res = [ 0u8 ; constants:: SECRET_KEY_SIZE ] ;
117117 match from_hex ( s, & mut res) {
118- Ok ( constants:: SECRET_KEY_SIZE ) => SecretKey :: from_slice ( & res) ,
118+ Ok ( constants:: SECRET_KEY_SIZE ) => SecretKey :: from_byte_array ( & res) ,
119119 _ => Err ( Error :: InvalidSecretKey ) ,
120120 }
121121 }
@@ -138,7 +138,7 @@ impl str::FromStr for SecretKey {
138138/// use secp256k1::{SecretKey, Secp256k1, PublicKey};
139139///
140140/// let secp = Secp256k1::new();
141- /// let secret_key = SecretKey::from_slice (&[0xcd; 32]).expect("32 bytes, within curve order");
141+ /// let secret_key = SecretKey::from_byte_array (&[0xcd; 32]).expect("32 bytes, within curve order");
142142/// let public_key = PublicKey::from_secret_key(&secp, &secret_key);
143143/// # }
144144/// ```
@@ -168,9 +168,13 @@ impl str::FromStr for PublicKey {
168168 fn from_str ( s : & str ) -> Result < PublicKey , Error > {
169169 let mut res = [ 0u8 ; constants:: UNCOMPRESSED_PUBLIC_KEY_SIZE ] ;
170170 match from_hex ( s, & mut res) {
171- Ok ( constants:: PUBLIC_KEY_SIZE ) =>
172- PublicKey :: from_slice ( & res[ 0 ..constants:: PUBLIC_KEY_SIZE ] ) ,
173- Ok ( constants:: UNCOMPRESSED_PUBLIC_KEY_SIZE ) => PublicKey :: from_slice ( & res) ,
171+ Ok ( constants:: PUBLIC_KEY_SIZE ) => {
172+ let bytes: [ u8 ; constants:: PUBLIC_KEY_SIZE ] =
173+ res[ 0 ..constants:: PUBLIC_KEY_SIZE ] . try_into ( ) . unwrap ( ) ;
174+ PublicKey :: from_byte_array_compressed ( & bytes)
175+ }
176+ Ok ( constants:: UNCOMPRESSED_PUBLIC_KEY_SIZE ) =>
177+ PublicKey :: from_byte_array_uncompressed ( & res) ,
174178 _ => Err ( Error :: InvalidPublicKey ) ,
175179 }
176180 }
@@ -211,6 +215,7 @@ impl SecretKey {
211215 /// use secp256k1::SecretKey;
212216 /// let sk = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order");
213217 /// ```
218+ #[ deprecated( since = "TBD" , note = "Use `from_byte_array` instead." ) ]
214219 #[ inline]
215220 pub fn from_slice ( data : & [ u8 ] ) -> Result < SecretKey , Error > {
216221 match <[ u8 ; constants:: SECRET_KEY_SIZE ] >:: try_from ( data) {
@@ -362,7 +367,7 @@ impl SecretKey {
362367impl < T : ThirtyTwoByteHash > From < T > for SecretKey {
363368 /// Converts a 32-byte hash directly to a secret key without error paths.
364369 fn from ( t : T ) -> SecretKey {
365- SecretKey :: from_slice ( & t. into_32 ( ) ) . expect ( "failed to create secret key" )
370+ SecretKey :: from_byte_array ( & t. into_32 ( ) ) . expect ( "failed to create secret key" )
366371 }
367372}
368373
@@ -542,7 +547,7 @@ impl PublicKey {
542547 } ;
543548 buf[ 1 ..] . clone_from_slice ( & pk. serialize ( ) ) ;
544549
545- PublicKey :: from_slice ( & buf) . expect ( "we know the buffer is valid" )
550+ PublicKey :: from_byte_array_compressed ( & buf) . expect ( "we know the buffer is valid" )
546551 }
547552
548553 #[ inline]
@@ -1156,8 +1161,7 @@ impl str::FromStr for XOnlyPublicKey {
11561161 fn from_str ( s : & str ) -> Result < XOnlyPublicKey , Error > {
11571162 let mut res = [ 0u8 ; constants:: SCHNORR_PUBLIC_KEY_SIZE ] ;
11581163 match from_hex ( s, & mut res) {
1159- Ok ( constants:: SCHNORR_PUBLIC_KEY_SIZE ) =>
1160- XOnlyPublicKey :: from_slice ( & res[ 0 ..constants:: SCHNORR_PUBLIC_KEY_SIZE ] ) ,
1164+ Ok ( constants:: SCHNORR_PUBLIC_KEY_SIZE ) => XOnlyPublicKey :: from_byte_array ( & res) ,
11611165 _ => Err ( Error :: InvalidPublicKey ) ,
11621166 }
11631167 }
@@ -1203,6 +1207,7 @@ impl XOnlyPublicKey {
12031207 ///
12041208 /// Returns [`Error::InvalidPublicKey`] if the length of the data slice is not 32 bytes or the
12051209 /// slice does not represent a valid Secp256k1 point x coordinate.
1210+ #[ deprecated( since = "TBD" , note = "Use `from_byte_array` instead." ) ]
12061211 #[ inline]
12071212 pub fn from_slice ( data : & [ u8 ] ) -> Result < XOnlyPublicKey , Error > {
12081213 match <[ u8 ; constants:: SCHNORR_PUBLIC_KEY_SIZE ] >:: try_from ( data) {
0 commit comments