@@ -19,7 +19,8 @@ use crate::Error::{self, InvalidPublicKey, InvalidPublicKeySum, InvalidSecretKey
1919#[ cfg( feature = "global-context" ) ]
2020use crate :: SECP256K1 ;
2121use crate :: {
22- constants, ecdsa, from_hex, schnorr, Message , Scalar , Secp256k1 , Signing , Verification ,
22+ constants, ecdsa, from_hex, schnorr, AllPreallocated , Message , Scalar , Secp256k1 , Signing ,
23+ Verification ,
2324} ;
2425
2526/// Secret key - a 256-bit key used to create ECDSA and Taproot signatures.
@@ -1066,20 +1067,14 @@ impl<'a> From<&'a Keypair> for PublicKey {
10661067 fn from ( pair : & ' a Keypair ) -> Self { PublicKey :: from_keypair ( pair) }
10671068}
10681069
1069- #[ cfg( any( feature = "global-context" , feature = "alloc" ) ) ]
10701070impl str:: FromStr for Keypair {
10711071 type Err = Error ;
10721072
1073- #[ allow( unused_variables, unreachable_code) ] // When built with no default features.
10741073 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
1075- #[ cfg( feature = "global-context" ) ]
1076- let ctx = SECP256K1 ;
1077-
1078- #[ cfg( all( not( feature = "global-context" ) , feature = "alloc" ) ) ]
1079- let ctx = Secp256k1 :: signing_only ( ) ;
1080-
1081- #[ allow( clippy:: needless_borrow) ]
1082- Keypair :: from_seckey_str ( & ctx, s)
1074+ crate :: with_global_context (
1075+ |secp : & Secp256k1 < AllPreallocated > | Self :: from_seckey_str ( secp, s) ,
1076+ None ,
1077+ )
10831078 }
10841079}
10851080
@@ -1103,8 +1098,6 @@ impl serde::Serialize for Keypair {
11031098}
11041099
11051100#[ cfg( feature = "serde" ) ]
1106- #[ allow( unused_variables) ] // For `data` under some feature combinations (the unconditional panic below).
1107- #[ cfg( all( feature = "serde" , any( feature = "global-context" , feature = "alloc" ) ) ) ]
11081101impl < ' de > serde:: Deserialize < ' de > for Keypair {
11091102 fn deserialize < D : serde:: Deserializer < ' de > > ( d : D ) -> Result < Self , D :: Error > {
11101103 if d. is_human_readable ( ) {
@@ -1113,14 +1106,10 @@ impl<'de> serde::Deserialize<'de> for Keypair {
11131106 ) )
11141107 } else {
11151108 let visitor = super :: serde_util:: Tuple32Visitor :: new ( "raw 32 bytes Keypair" , |data| {
1116- #[ cfg( feature = "global-context" ) ]
1117- let ctx = SECP256K1 ;
1118-
1119- #[ cfg( all( not( feature = "global-context" ) , feature = "alloc" ) ) ]
1120- let ctx = Secp256k1 :: signing_only ( ) ;
1121-
1122- #[ allow( clippy:: needless_borrow) ]
1123- Keypair :: from_seckey_byte_array ( & ctx, data)
1109+ crate :: with_global_context (
1110+ |secp : & Secp256k1 < AllPreallocated > | Self :: from_seckey_byte_array ( secp, data) ,
1111+ None ,
1112+ )
11241113 } ) ;
11251114 d. deserialize_tuple ( constants:: SECRET_KEY_SIZE , visitor)
11261115 }
0 commit comments