Merge rust-bitcoin/rust-secp256k1#728: Feature gate the `Keypair::FromStr` impl
d600a6cf00
Feature gate the Keypair::FromStr impl (Tobin C. Harding) Pull request description: Currently we are panicing if neither `global-context` or `alloc` features are enabled. We do not need to do so, we can just disable the whole impl of `FromStr`. This was pulled out of #699. ACKs for top commit: apoelstra: ACKd600a6cf00
successfully ran local tests Kixunil: ACKd600a6cf00
Tree-SHA512: 940bec95ce732b4bc482e23da114cb03b767780f93777621c9d0985d1288e36756bdf6f050172eac00f89b6f39aa0efdb30cc77425b6f87505659c8c012981ca
This commit is contained in:
commit
a3aa0d980d
17
src/key.rs
17
src/key.rs
|
@ -1000,6 +1000,7 @@ impl<'a> From<&'a Keypair> for PublicKey {
|
|||
fn from(pair: &'a Keypair) -> Self { PublicKey::from_keypair(pair) }
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "global-context", feature = "alloc"))]
|
||||
impl str::FromStr for Keypair {
|
||||
type Err = Error;
|
||||
|
||||
|
@ -1011,9 +1012,6 @@ impl str::FromStr for Keypair {
|
|||
#[cfg(all(not(feature = "global-context"), feature = "alloc"))]
|
||||
let ctx = Secp256k1::signing_only();
|
||||
|
||||
#[cfg(not(any(feature = "global-context", feature = "alloc")))]
|
||||
let ctx: Secp256k1<crate::SignOnlyPreallocated> = panic!("The previous implementation was panicking too, please enable the global-context feature of rust-secp256k1");
|
||||
|
||||
#[allow(clippy::needless_borrow)]
|
||||
Keypair::from_seckey_str(&ctx, s)
|
||||
}
|
||||
|
@ -1040,7 +1038,7 @@ impl serde::Serialize for Keypair {
|
|||
|
||||
#[cfg(feature = "serde")]
|
||||
#[allow(unused_variables)] // For `data` under some feature combinations (the unconditional panic below).
|
||||
#[allow(unreachable_code)] // For `Keypair::from_seckey_slice` after unconditional panic.
|
||||
#[cfg(all(feature = "serde", any(feature = "global-context", feature = "alloc")))]
|
||||
impl<'de> serde::Deserialize<'de> for Keypair {
|
||||
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
|
||||
if d.is_human_readable() {
|
||||
|
@ -1055,9 +1053,6 @@ impl<'de> serde::Deserialize<'de> for Keypair {
|
|||
#[cfg(all(not(feature = "global-context"), feature = "alloc"))]
|
||||
let ctx = Secp256k1::signing_only();
|
||||
|
||||
#[cfg(not(any(feature = "global-context", feature = "alloc")))]
|
||||
let ctx: Secp256k1<crate::SignOnlyPreallocated> = panic!("cannot deserialize key pair without a context (please enable either the global-context or alloc feature)");
|
||||
|
||||
#[allow(clippy::needless_borrow)]
|
||||
Keypair::from_seckey_slice(&ctx, data)
|
||||
});
|
||||
|
@ -2423,14 +2418,6 @@ mod test {
|
|||
.collect::<Vec<_>>();
|
||||
serde_test::assert_tokens(&keypair.compact(), &tokens);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "The previous implementation was panicking too")]
|
||||
#[cfg(not(any(feature = "alloc", feature = "global-context")))]
|
||||
fn test_parse_keypair_no_alloc_panic() {
|
||||
let key_hex = "4242424242424242424242424242424242424242424242424242424242424242";
|
||||
let _: Keypair = key_hex.parse().expect("We shouldn't even get this far");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(bench)]
|
||||
|
|
Loading…
Reference in New Issue