Skip to content

Commit 0a46bf9

Browse files
committed
Feature gate the Keypair::FromStr impl
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`.
1 parent 4428e08 commit 0a46bf9

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

src/key.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ impl<'a> From<&'a Keypair> for PublicKey {
992992
fn from(pair: &'a Keypair) -> Self { PublicKey::from_keypair(pair) }
993993
}
994994

995+
#[cfg(any(feature = "global-context", feature = "alloc"))]
995996
impl str::FromStr for Keypair {
996997
type Err = Error;
997998

@@ -1003,9 +1004,6 @@ impl str::FromStr for Keypair {
10031004
#[cfg(all(not(feature = "global-context"), feature = "alloc"))]
10041005
let ctx = Secp256k1::signing_only();
10051006

1006-
#[cfg(not(any(feature = "global-context", feature = "alloc")))]
1007-
let ctx: Secp256k1<crate::SignOnlyPreallocated> = panic!("The previous implementation was panicking too, please enable the global-context feature of rust-secp256k1");
1008-
10091007
#[allow(clippy::needless_borrow)]
10101008
Keypair::from_seckey_str(&ctx, s)
10111009
}
@@ -2412,14 +2410,6 @@ mod test {
24122410
.collect::<Vec<_>>();
24132411
serde_test::assert_tokens(&keypair.compact(), &tokens);
24142412
}
2415-
2416-
#[test]
2417-
#[should_panic(expected = "The previous implementation was panicking too")]
2418-
#[cfg(not(any(feature = "alloc", feature = "global-context")))]
2419-
fn test_parse_keypair_no_alloc_panic() {
2420-
let key_hex = "4242424242424242424242424242424242424242424242424242424242424242";
2421-
let _: Keypair = key_hex.parse().expect("We shouldn't even get this far");
2422-
}
24232413
}
24242414

24252415
#[cfg(bench)]

0 commit comments

Comments
 (0)