@@ -20,7 +20,8 @@ use crate::ThirtyTwoByteHash;
20
20
#[ cfg( feature = "global-context" ) ]
21
21
use crate :: SECP256K1 ;
22
22
use crate :: {
23
- constants, ecdsa, from_hex, schnorr, Message , Scalar , Secp256k1 , Signing , Verification ,
23
+ constants, ecdsa, from_hex, schnorr, AllPreallocated , Message , Scalar , Secp256k1 , Signing ,
24
+ Verification ,
24
25
} ;
25
26
26
27
/// Secret key - a 256-bit key used to create ECDSA and Taproot signatures.
@@ -1076,20 +1077,14 @@ impl<'a> From<&'a Keypair> for PublicKey {
1076
1077
fn from ( pair : & ' a Keypair ) -> Self { PublicKey :: from_keypair ( pair) }
1077
1078
}
1078
1079
1079
- #[ cfg( any( feature = "global-context" , feature = "alloc" ) ) ]
1080
1080
impl str:: FromStr for Keypair {
1081
1081
type Err = Error ;
1082
1082
1083
- #[ allow( unused_variables, unreachable_code) ] // When built with no default features.
1084
1083
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
1085
- #[ cfg( feature = "global-context" ) ]
1086
- let ctx = SECP256K1 ;
1087
-
1088
- #[ cfg( all( not( feature = "global-context" ) , feature = "alloc" ) ) ]
1089
- let ctx = Secp256k1 :: signing_only ( ) ;
1090
-
1091
- #[ allow( clippy:: needless_borrow) ]
1092
- Keypair :: from_seckey_str ( & ctx, s)
1084
+ crate :: with_global_context (
1085
+ |secp : & Secp256k1 < AllPreallocated > | Self :: from_seckey_str ( secp, s) ,
1086
+ None ,
1087
+ )
1093
1088
}
1094
1089
}
1095
1090
@@ -1113,8 +1108,6 @@ impl serde::Serialize for Keypair {
1113
1108
}
1114
1109
1115
1110
#[ cfg( feature = "serde" ) ]
1116
- #[ allow( unused_variables) ] // For `data` under some feature combinations (the unconditional panic below).
1117
- #[ cfg( all( feature = "serde" , any( feature = "global-context" , feature = "alloc" ) ) ) ]
1118
1111
impl < ' de > serde:: Deserialize < ' de > for Keypair {
1119
1112
fn deserialize < D : serde:: Deserializer < ' de > > ( d : D ) -> Result < Self , D :: Error > {
1120
1113
if d. is_human_readable ( ) {
@@ -1123,14 +1116,10 @@ impl<'de> serde::Deserialize<'de> for Keypair {
1123
1116
) )
1124
1117
} else {
1125
1118
let visitor = super :: serde_util:: Tuple32Visitor :: new ( "raw 32 bytes Keypair" , |data| {
1126
- #[ cfg( feature = "global-context" ) ]
1127
- let ctx = SECP256K1 ;
1128
-
1129
- #[ cfg( all( not( feature = "global-context" ) , feature = "alloc" ) ) ]
1130
- let ctx = Secp256k1 :: signing_only ( ) ;
1131
-
1132
- #[ allow( clippy:: needless_borrow) ]
1133
- Keypair :: from_seckey_byte_array ( & ctx, data)
1119
+ crate :: with_global_context (
1120
+ |secp : & Secp256k1 < AllPreallocated > | Self :: from_seckey_byte_array ( secp, data) ,
1121
+ None ,
1122
+ )
1134
1123
} ) ;
1135
1124
d. deserialize_tuple ( constants:: SECRET_KEY_SIZE , visitor)
1136
1125
}
0 commit comments