@@ -115,7 +115,7 @@ impl str::FromStr for SecretKey {
115
115
fn from_str ( s : & str ) -> Result < SecretKey , Error > {
116
116
let mut res = [ 0u8 ; constants:: SECRET_KEY_SIZE ] ;
117
117
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) ,
119
119
_ => Err ( Error :: InvalidSecretKey ) ,
120
120
}
121
121
}
@@ -138,7 +138,7 @@ impl str::FromStr for SecretKey {
138
138
/// use secp256k1::{SecretKey, Secp256k1, PublicKey};
139
139
///
140
140
/// 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");
142
142
/// let public_key = PublicKey::from_secret_key(&secp, &secret_key);
143
143
/// # }
144
144
/// ```
@@ -168,9 +168,13 @@ impl str::FromStr for PublicKey {
168
168
fn from_str ( s : & str ) -> Result < PublicKey , Error > {
169
169
let mut res = [ 0u8 ; constants:: UNCOMPRESSED_PUBLIC_KEY_SIZE ] ;
170
170
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) ,
174
178
_ => Err ( Error :: InvalidPublicKey ) ,
175
179
}
176
180
}
@@ -211,6 +215,7 @@ impl SecretKey {
211
215
/// use secp256k1::SecretKey;
212
216
/// let sk = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order");
213
217
/// ```
218
+ #[ deprecated( since = "TBD" , note = "Use `from_byte_array` instead." ) ]
214
219
#[ inline]
215
220
pub fn from_slice ( data : & [ u8 ] ) -> Result < SecretKey , Error > {
216
221
match <[ u8 ; constants:: SECRET_KEY_SIZE ] >:: try_from ( data) {
@@ -362,7 +367,7 @@ impl SecretKey {
362
367
impl < T : ThirtyTwoByteHash > From < T > for SecretKey {
363
368
/// Converts a 32-byte hash directly to a secret key without error paths.
364
369
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" )
366
371
}
367
372
}
368
373
@@ -542,7 +547,7 @@ impl PublicKey {
542
547
} ;
543
548
buf[ 1 ..] . clone_from_slice ( & pk. serialize ( ) ) ;
544
549
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" )
546
551
}
547
552
548
553
#[ inline]
@@ -1156,8 +1161,7 @@ impl str::FromStr for XOnlyPublicKey {
1156
1161
fn from_str ( s : & str ) -> Result < XOnlyPublicKey , Error > {
1157
1162
let mut res = [ 0u8 ; constants:: SCHNORR_PUBLIC_KEY_SIZE ] ;
1158
1163
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) ,
1161
1165
_ => Err ( Error :: InvalidPublicKey ) ,
1162
1166
}
1163
1167
}
@@ -1203,6 +1207,7 @@ impl XOnlyPublicKey {
1203
1207
///
1204
1208
/// Returns [`Error::InvalidPublicKey`] if the length of the data slice is not 32 bytes or the
1205
1209
/// slice does not represent a valid Secp256k1 point x coordinate.
1210
+ #[ deprecated( since = "TBD" , note = "Use `from_byte_array` instead." ) ]
1206
1211
#[ inline]
1207
1212
pub fn from_slice ( data : & [ u8 ] ) -> Result < XOnlyPublicKey , Error > {
1208
1213
match <[ u8 ; constants:: SCHNORR_PUBLIC_KEY_SIZE ] >:: try_from ( data) {
0 commit comments