@@ -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_byte_array ( & 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_byte_array(& [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
/// ```
@@ -175,10 +175,10 @@ impl str::FromStr for PublicKey {
175
175
Ok ( constants:: PUBLIC_KEY_SIZE ) => {
176
176
let bytes: [ u8 ; constants:: PUBLIC_KEY_SIZE ] =
177
177
res[ 0 ..constants:: PUBLIC_KEY_SIZE ] . try_into ( ) . unwrap ( ) ;
178
- PublicKey :: from_byte_array_compressed ( & bytes)
178
+ PublicKey :: from_byte_array_compressed ( bytes)
179
179
}
180
180
Ok ( constants:: UNCOMPRESSED_PUBLIC_KEY_SIZE ) =>
181
- PublicKey :: from_byte_array_uncompressed ( & res) ,
181
+ PublicKey :: from_byte_array_uncompressed ( res) ,
182
182
_ => Err ( Error :: InvalidPublicKey ) ,
183
183
}
184
184
}
@@ -223,7 +223,7 @@ impl SecretKey {
223
223
#[ inline]
224
224
pub fn from_slice ( data : & [ u8 ] ) -> Result < SecretKey , Error > {
225
225
match <[ u8 ; constants:: SECRET_KEY_SIZE ] >:: try_from ( data) {
226
- Ok ( data) => Self :: from_byte_array ( & data) ,
226
+ Ok ( data) => Self :: from_byte_array ( data) ,
227
227
Err ( _) => Err ( InvalidSecretKey ) ,
228
228
}
229
229
}
@@ -234,18 +234,18 @@ impl SecretKey {
234
234
///
235
235
/// ```
236
236
/// use secp256k1::SecretKey;
237
- /// let sk = SecretKey::from_byte_array(& [0xcd; 32]).expect("32 bytes, within curve order");
237
+ /// let sk = SecretKey::from_byte_array([0xcd; 32]).expect("32 bytes, within curve order");
238
238
/// ```
239
239
#[ inline]
240
- pub fn from_byte_array ( data : & [ u8 ; constants:: SECRET_KEY_SIZE ] ) -> Result < SecretKey , Error > {
240
+ pub fn from_byte_array ( data : [ u8 ; constants:: SECRET_KEY_SIZE ] ) -> Result < SecretKey , Error > {
241
241
unsafe {
242
242
if ffi:: secp256k1_ec_seckey_verify ( ffi:: secp256k1_context_no_precomp, data. as_c_ptr ( ) )
243
243
== 0
244
244
{
245
245
return Err ( InvalidSecretKey ) ;
246
246
}
247
247
}
248
- Ok ( SecretKey ( * data) )
248
+ Ok ( SecretKey ( data) )
249
249
}
250
250
251
251
/// Creates a new secret key using data from BIP-340 [`Keypair`].
@@ -373,7 +373,7 @@ impl SecretKey {
373
373
impl < T : ThirtyTwoByteHash > From < T > for SecretKey {
374
374
/// Converts a 32-byte hash directly to a secret key without error paths.
375
375
fn from ( t : T ) -> SecretKey {
376
- SecretKey :: from_byte_array ( & t. into_32 ( ) ) . expect ( "failed to create secret key" )
376
+ SecretKey :: from_byte_array ( t. into_32 ( ) ) . expect ( "failed to create secret key" )
377
377
}
378
378
}
379
379
@@ -403,7 +403,7 @@ impl<'de> serde::Deserialize<'de> for SecretKey {
403
403
} else {
404
404
let visitor =
405
405
super :: serde_util:: Tuple32Visitor :: new ( "raw 32 bytes SecretKey" , |bytes| {
406
- SecretKey :: from_byte_array ( & bytes)
406
+ SecretKey :: from_byte_array ( bytes)
407
407
} ) ;
408
408
d. deserialize_tuple ( constants:: SECRET_KEY_SIZE , visitor)
409
409
}
@@ -464,10 +464,10 @@ impl PublicKey {
464
464
pub fn from_slice ( data : & [ u8 ] ) -> Result < PublicKey , Error > {
465
465
match data. len ( ) {
466
466
constants:: PUBLIC_KEY_SIZE => PublicKey :: from_byte_array_compressed (
467
- & <[ u8 ; constants:: PUBLIC_KEY_SIZE ] >:: try_from ( data) . unwrap ( ) ,
467
+ <[ u8 ; constants:: PUBLIC_KEY_SIZE ] >:: try_from ( data) . unwrap ( ) ,
468
468
) ,
469
469
constants:: UNCOMPRESSED_PUBLIC_KEY_SIZE => PublicKey :: from_byte_array_uncompressed (
470
- & <[ u8 ; constants:: UNCOMPRESSED_PUBLIC_KEY_SIZE ] >:: try_from ( data) . unwrap ( ) ,
470
+ <[ u8 ; constants:: UNCOMPRESSED_PUBLIC_KEY_SIZE ] >:: try_from ( data) . unwrap ( ) ,
471
471
) ,
472
472
_ => Err ( InvalidPublicKey ) ,
473
473
}
@@ -476,7 +476,7 @@ impl PublicKey {
476
476
/// Creates a public key from a serialized array in compressed format.
477
477
#[ inline]
478
478
pub fn from_byte_array_compressed (
479
- data : & [ u8 ; constants:: PUBLIC_KEY_SIZE ] ,
479
+ data : [ u8 ; constants:: PUBLIC_KEY_SIZE ] ,
480
480
) -> Result < PublicKey , Error > {
481
481
unsafe {
482
482
let mut pk = ffi:: PublicKey :: new ( ) ;
@@ -497,7 +497,7 @@ impl PublicKey {
497
497
/// Creates a public key from a serialized array in uncompressed format.
498
498
#[ inline]
499
499
pub fn from_byte_array_uncompressed (
500
- data : & [ u8 ; constants:: UNCOMPRESSED_PUBLIC_KEY_SIZE ] ,
500
+ data : [ u8 ; constants:: UNCOMPRESSED_PUBLIC_KEY_SIZE ] ,
501
501
) -> Result < PublicKey , Error > {
502
502
unsafe {
503
503
let mut pk = ffi:: PublicKey :: new ( ) ;
@@ -553,7 +553,7 @@ impl PublicKey {
553
553
} ;
554
554
buf[ 1 ..] . clone_from_slice ( & pk. serialize ( ) ) ;
555
555
556
- PublicKey :: from_byte_array_compressed ( & buf) . expect ( "we know the buffer is valid" )
556
+ PublicKey :: from_byte_array_compressed ( buf) . expect ( "we know the buffer is valid" )
557
557
}
558
558
559
559
#[ inline]
@@ -792,7 +792,7 @@ impl<'de> serde::Deserialize<'de> for PublicKey {
792
792
} else {
793
793
let visitor =
794
794
super :: serde_util:: Tuple33Visitor :: new ( "33 bytes compressed public key" , |bytes| {
795
- PublicKey :: from_byte_array_compressed ( & bytes)
795
+ PublicKey :: from_byte_array_compressed ( bytes)
796
796
} ) ;
797
797
d. deserialize_tuple ( constants:: PUBLIC_KEY_SIZE , visitor)
798
798
}
@@ -1193,7 +1193,7 @@ impl str::FromStr for XOnlyPublicKey {
1193
1193
fn from_str ( s : & str ) -> Result < XOnlyPublicKey , Error > {
1194
1194
let mut res = [ 0u8 ; constants:: SCHNORR_PUBLIC_KEY_SIZE ] ;
1195
1195
match from_hex ( s, & mut res) {
1196
- Ok ( constants:: SCHNORR_PUBLIC_KEY_SIZE ) => XOnlyPublicKey :: from_byte_array ( & res) ,
1196
+ Ok ( constants:: SCHNORR_PUBLIC_KEY_SIZE ) => XOnlyPublicKey :: from_byte_array ( res) ,
1197
1197
_ => Err ( Error :: InvalidPublicKey ) ,
1198
1198
}
1199
1199
}
@@ -1243,7 +1243,7 @@ impl XOnlyPublicKey {
1243
1243
#[ inline]
1244
1244
pub fn from_slice ( data : & [ u8 ] ) -> Result < XOnlyPublicKey , Error > {
1245
1245
match <[ u8 ; constants:: SCHNORR_PUBLIC_KEY_SIZE ] >:: try_from ( data) {
1246
- Ok ( data) => Self :: from_byte_array ( & data) ,
1246
+ Ok ( data) => Self :: from_byte_array ( data) ,
1247
1247
Err ( _) => Err ( InvalidPublicKey ) ,
1248
1248
}
1249
1249
}
@@ -1256,7 +1256,7 @@ impl XOnlyPublicKey {
1256
1256
/// x coordinate.
1257
1257
#[ inline]
1258
1258
pub fn from_byte_array (
1259
- data : & [ u8 ; constants:: SCHNORR_PUBLIC_KEY_SIZE ] ,
1259
+ data : [ u8 ; constants:: SCHNORR_PUBLIC_KEY_SIZE ] ,
1260
1260
) -> Result < XOnlyPublicKey , Error > {
1261
1261
unsafe {
1262
1262
let mut pk = ffi:: XOnlyPublicKey :: new ( ) ;
@@ -1609,7 +1609,7 @@ impl<'de> serde::Deserialize<'de> for XOnlyPublicKey {
1609
1609
} else {
1610
1610
let visitor = super :: serde_util:: Tuple32Visitor :: new (
1611
1611
"raw 32 bytes schnorr public key" ,
1612
- |bytes| XOnlyPublicKey :: from_byte_array ( & bytes ) ,
1612
+ XOnlyPublicKey :: from_byte_array,
1613
1613
) ;
1614
1614
d. deserialize_tuple ( constants:: SCHNORR_PUBLIC_KEY_SIZE , visitor)
1615
1615
}
0 commit comments