@@ -19,7 +19,8 @@ use crate::Error::{self, InvalidPublicKey, InvalidPublicKeySum, InvalidSecretKey
19
19
#[ cfg( feature = "global-context" ) ]
20
20
use crate :: SECP256K1 ;
21
21
use 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 ,
23
24
} ;
24
25
25
26
/// Secret key - a 256-bit key used to create ECDSA and Taproot signatures.
@@ -1066,20 +1067,14 @@ impl<'a> From<&'a Keypair> for PublicKey {
1066
1067
fn from ( pair : & ' a Keypair ) -> Self { PublicKey :: from_keypair ( pair) }
1067
1068
}
1068
1069
1069
- #[ cfg( any( feature = "global-context" , feature = "alloc" ) ) ]
1070
1070
impl str:: FromStr for Keypair {
1071
1071
type Err = Error ;
1072
1072
1073
- #[ allow( unused_variables, unreachable_code) ] // When built with no default features.
1074
1073
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
+ )
1083
1078
}
1084
1079
}
1085
1080
@@ -1103,8 +1098,6 @@ impl serde::Serialize for Keypair {
1103
1098
}
1104
1099
1105
1100
#[ 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" ) ) ) ]
1108
1101
impl < ' de > serde:: Deserialize < ' de > for Keypair {
1109
1102
fn deserialize < D : serde:: Deserializer < ' de > > ( d : D ) -> Result < Self , D :: Error > {
1110
1103
if d. is_human_readable ( ) {
@@ -1113,14 +1106,10 @@ impl<'de> serde::Deserialize<'de> for Keypair {
1113
1106
) )
1114
1107
} else {
1115
1108
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
+ )
1124
1113
} ) ;
1125
1114
d. deserialize_tuple ( constants:: SECRET_KEY_SIZE , visitor)
1126
1115
}
0 commit comments