Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make static-context and lazy-static-context addictive #82

Merged
merged 2 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ default = ["std", "hmac", "static-context"]
std = ["libsecp256k1-core/std", "sha2/std", "rand/std", "serde/std", "base64/std"]
hmac = ["hmac-drbg", "sha2", "typenum"]
static-context = []
lazy-static-context = ["lazy_static", "std"]
lazy-static-context = ["static-context", "lazy_static", "std"]

[workspace]
members = [
Expand Down
7 changes: 2 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ use crate::{
util::{Decoder, SignatureArray},
};

#[cfg(all(feature = "static-context", feature = "lazy-static-context"))]
compile_error!("Should only enable one of static-context or lazy-static-context");

#[cfg(feature = "lazy-static-context")]
lazy_static::lazy_static! {
/// A static ECMult context.
Expand All @@ -49,13 +46,13 @@ lazy_static::lazy_static! {
pub static ref ECMULT_GEN_CONTEXT: Box<ECMultGenContext> = ECMultGenContext::new_boxed();
}

#[cfg(feature = "static-context")]
#[cfg(all(feature = "static-context", not(feature = "lazy-static-context")))]
/// A static ECMult context.
// Correct `pre_g` values are fed into `ECMultContext::new_from_raw`, generated by build script.
Comment on lines 50 to 51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// A static ECMult context.
// Correct `pre_g` values are fed into `ECMultContext::new_from_raw`, generated by build script.
/// A static ECMult context. Requires that the `static-context` to be enabled and that `lazy-static-context` is **not** enabled.
/// Correct `pre_g` values are fed into `ECMultContext::new_from_raw`, generated by build script.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ECMULT_CONTEXT is defined either here or through lazy_static. It is always available either with static-context or lazy-static-context.

The second line is related to implementation details of how this is generated, so it doesn't really fit the docs.

pub static ECMULT_CONTEXT: ECMultContext =
unsafe { ECMultContext::new_from_raw(include!(concat!(env!("OUT_DIR"), "/const.rs"))) };

#[cfg(feature = "static-context")]
#[cfg(all(feature = "static-context", not(feature = "lazy-static-context")))]
/// A static ECMultGen context.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same note in the docs here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

// Correct `prec` values are fed into `ECMultGenContext::new_from_raw`, generated by build script.
pub static ECMULT_GEN_CONTEXT: ECMultGenContext =
Expand Down