@@ -16,9 +16,7 @@ use crate::ffi::{self, CPtr};
16
16
use crate :: Error :: { self , InvalidPublicKey , InvalidPublicKeySum , InvalidSecretKey } ;
17
17
#[ cfg( feature = "global-context" ) ]
18
18
use crate :: SECP256K1 ;
19
- use crate :: {
20
- constants, ecdsa, from_hex, schnorr, Message , Scalar , Secp256k1 , Signing , Verification ,
21
- } ;
19
+ use crate :: { constants, ecdsa, hex, schnorr, Message , Scalar , Secp256k1 , Signing , Verification } ;
22
20
#[ cfg( feature = "hashes" ) ]
23
21
use crate :: { hashes, ThirtyTwoByteHash } ;
24
22
@@ -114,7 +112,7 @@ impl str::FromStr for SecretKey {
114
112
type Err = Error ;
115
113
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
116
114
let mut res = [ 0u8 ; constants:: SECRET_KEY_SIZE ] ;
117
- match from_hex ( s, & mut res) {
115
+ match hex :: from_hex ( s, & mut res) {
118
116
Ok ( constants:: SECRET_KEY_SIZE ) => SecretKey :: from_slice ( & res) ,
119
117
_ => Err ( Error :: InvalidSecretKey ) ,
120
118
}
@@ -167,7 +165,7 @@ impl str::FromStr for PublicKey {
167
165
type Err = Error ;
168
166
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
169
167
let mut res = [ 0u8 ; constants:: UNCOMPRESSED_PUBLIC_KEY_SIZE ] ;
170
- match from_hex ( s, & mut res) {
168
+ match hex :: from_hex ( s, & mut res) {
171
169
Ok ( constants:: PUBLIC_KEY_SIZE ) =>
172
170
PublicKey :: from_slice ( & res[ 0 ..constants:: PUBLIC_KEY_SIZE ] ) ,
173
171
Ok ( constants:: UNCOMPRESSED_PUBLIC_KEY_SIZE ) => PublicKey :: from_slice ( & res) ,
@@ -385,7 +383,7 @@ impl serde::Serialize for SecretKey {
385
383
fn serialize < S : serde:: Serializer > ( & self , s : S ) -> Result < S :: Ok , S :: Error > {
386
384
if s. is_human_readable ( ) {
387
385
let mut buf = [ 0u8 ; constants:: SECRET_KEY_SIZE * 2 ] ;
388
- s. serialize_str ( crate :: to_hex ( & self . 0 , & mut buf) . expect ( "fixed-size hex serialization" ) )
386
+ s. serialize_str ( hex :: to_hex ( & self . 0 , & mut buf) . expect ( "fixed-size hex serialization" ) )
389
387
} else {
390
388
let mut tuple = s. serialize_tuple ( constants:: SECRET_KEY_SIZE ) ?;
391
389
for byte in self . 0 . iter ( ) {
@@ -859,7 +857,7 @@ impl Keypair {
859
857
#[ inline]
860
858
pub fn from_seckey_str < C : Signing > ( secp : & Secp256k1 < C > , s : & str ) -> Result < Keypair , Error > {
861
859
let mut res = [ 0u8 ; constants:: SECRET_KEY_SIZE ] ;
862
- match from_hex ( s, & mut res) {
860
+ match hex :: from_hex ( s, & mut res) {
863
861
Ok ( constants:: SECRET_KEY_SIZE ) =>
864
862
Keypair :: from_seckey_slice ( secp, & res[ 0 ..constants:: SECRET_KEY_SIZE ] ) ,
865
863
_ => Err ( Error :: InvalidPublicKey ) ,
@@ -1041,8 +1039,7 @@ impl serde::Serialize for Keypair {
1041
1039
if s. is_human_readable ( ) {
1042
1040
let mut buf = [ 0u8 ; constants:: SECRET_KEY_SIZE * 2 ] ;
1043
1041
s. serialize_str (
1044
- crate :: to_hex ( & self . secret_bytes ( ) , & mut buf)
1045
- . expect ( "fixed-size hex serialization" ) ,
1042
+ hex:: to_hex ( & self . secret_bytes ( ) , & mut buf) . expect ( "fixed-size hex serialization" ) ,
1046
1043
)
1047
1044
} else {
1048
1045
let mut tuple = s. serialize_tuple ( constants:: SECRET_KEY_SIZE ) ?;
@@ -1134,7 +1131,7 @@ impl str::FromStr for XOnlyPublicKey {
1134
1131
type Err = Error ;
1135
1132
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
1136
1133
let mut res = [ 0u8 ; constants:: SCHNORR_PUBLIC_KEY_SIZE ] ;
1137
- match from_hex ( s, & mut res) {
1134
+ match hex :: from_hex ( s, & mut res) {
1138
1135
Ok ( constants:: SCHNORR_PUBLIC_KEY_SIZE ) =>
1139
1136
XOnlyPublicKey :: from_slice ( & res[ 0 ..constants:: SCHNORR_PUBLIC_KEY_SIZE ] ) ,
1140
1137
_ => Err ( Error :: InvalidPublicKey ) ,
@@ -1559,13 +1556,13 @@ mod test {
1559
1556
1560
1557
use super :: { Keypair , Parity , PublicKey , Secp256k1 , SecretKey , XOnlyPublicKey , * } ;
1561
1558
use crate :: Error :: { InvalidPublicKey , InvalidSecretKey } ;
1562
- use crate :: { constants, from_hex , to_hex , Scalar } ;
1559
+ use crate :: { constants, hex , Scalar } ;
1563
1560
1564
1561
#[ cfg( not( secp256k1_fuzz) ) ]
1565
1562
macro_rules! hex {
1566
1563
( $hex: expr) => { {
1567
1564
let mut result = vec![ 0 ; $hex. len( ) / 2 ] ;
1568
- from_hex( $hex, & mut result) . expect( "valid hex string" ) ;
1565
+ hex :: from_hex( $hex, & mut result) . expect( "valid hex string" ) ;
1569
1566
result
1570
1567
} } ;
1571
1568
}
@@ -1745,7 +1742,7 @@ mod test {
1745
1742
1746
1743
let mut buf = [ 0u8 ; constants:: SECRET_KEY_SIZE * 2 ] ;
1747
1744
assert_eq ! (
1748
- to_hex( & sk[ ..] , & mut buf) . unwrap( ) ,
1745
+ hex :: to_hex( & sk[ ..] , & mut buf) . unwrap( ) ,
1749
1746
"0100000000000000020000000000000003000000000000000400000000000000"
1750
1747
) ;
1751
1748
}
@@ -2422,7 +2419,7 @@ mod test {
2422
2419
let ctx = crate :: Secp256k1 :: new ( ) ;
2423
2420
let keypair = Keypair :: new ( & ctx, & mut rand:: thread_rng ( ) ) ;
2424
2421
let mut buf = [ 0_u8 ; constants:: SECRET_KEY_SIZE * 2 ] ; // Holds hex digits.
2425
- let s = to_hex ( & keypair. secret_key ( ) . secret_bytes ( ) , & mut buf) . unwrap ( ) ;
2422
+ let s = hex :: to_hex ( & keypair. secret_key ( ) . secret_bytes ( ) , & mut buf) . unwrap ( ) ;
2426
2423
let parsed_key = Keypair :: from_str ( s) . unwrap ( ) ;
2427
2424
assert_eq ! ( parsed_key, keypair) ;
2428
2425
}
0 commit comments