Skip to content

Commit

Permalink
Feature gate the Keypair::FromStr impl
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
tcharding committed Aug 8, 2024
1 parent 4428e08 commit 0a46bf9
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,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;

Expand All @@ -1003,9 +1004,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)
}
Expand Down Expand Up @@ -2412,14 +2410,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)]
Expand Down

0 comments on commit 0a46bf9

Please sign in to comment.