|
110 | 110 | //! Observe that the same code using, say [`signing_only`](struct.Secp256k1.html#method.signing_only)
|
111 | 111 | //! to generate a context would simply not compile.
|
112 | 112 | //!
|
| 113 | +//! ## Crate features/optional dependencies |
| 114 | +//! |
| 115 | +//! This crate provides the following opt-in Cargo features: |
| 116 | +//! |
| 117 | +//! * `std` - use standard Rust library, enabled by default. |
| 118 | +//! * `alloc` - use the `alloc` standard Rust library to provide heap allocations. |
| 119 | +//! * `rand` - use `rand` library to provide random generator (e.g. to generate keys). |
| 120 | +//! * `rand-std` - use `rand` library with its `std` feature enabled. (Implies `rand`.) |
| 121 | +//! * `recovery` - enable functions that can compute the public key from signature. |
| 122 | +//! * `lowmemory` - optimize the library for low-memory environments. |
| 123 | +//! * `global-context` - enable use of global secp256k1 context. (Implies `std`, `rand-std` and |
| 124 | +//! `global-context-less-secure`.) |
| 125 | +//! * `global-context-less-secure` - enables global context without extra sidechannel protection. |
| 126 | +//! * `serde` - implements serialization and deserialization for types in this crate using `serde`. |
| 127 | +//! * `bitcoin_hashes` - enables interaction with the `bitcoin-hashes` crate (e.g. conversions). |
113 | 128 |
|
114 | 129 | // Coding conventions
|
115 | 130 | #![deny(non_upper_case_globals)]
|
|
121 | 136 |
|
122 | 137 | #![cfg_attr(all(not(test), not(feature = "std")), no_std)]
|
123 | 138 | #![cfg_attr(all(test, feature = "unstable"), feature(test))]
|
| 139 | +#![cfg_attr(docsrs, feature(doc_cfg))] |
124 | 140 |
|
125 | 141 | #[macro_use]
|
126 | 142 | pub extern crate secp256k1_sys;
|
127 | 143 | pub use secp256k1_sys as ffi;
|
128 | 144 |
|
129 |
| -#[cfg(feature = "bitcoin_hashes")] pub extern crate bitcoin_hashes as hashes; |
130 |
| -#[cfg(all(test, feature = "unstable"))] extern crate test; |
131 |
| -#[cfg(any(test, feature = "rand"))] pub extern crate rand; |
132 |
| -#[cfg(any(test))] extern crate rand_core; |
133 |
| -#[cfg(feature = "serde")] pub extern crate serde; |
134 |
| -#[cfg(all(test, feature = "serde"))] extern crate serde_test; |
135 |
| -#[cfg(any(test, feature = "rand"))] use rand::Rng; |
136 |
| -#[cfg(any(test, feature = "std"))] extern crate core; |
137 |
| -#[cfg(all(test, target_arch = "wasm32"))] extern crate wasm_bindgen_test; |
138 |
| -#[cfg(feature = "alloc")] extern crate alloc; |
| 145 | +#[cfg(feature = "bitcoin_hashes")] |
| 146 | +#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin_hashes")))] |
| 147 | +pub extern crate bitcoin_hashes as hashes; |
| 148 | +#[cfg(all(test, feature = "unstable"))] |
| 149 | +extern crate test; |
| 150 | +#[cfg(any(test, feature = "rand"))] |
| 151 | +#[cfg_attr(docsrs, doc(cfg(feature = "rand")))] |
| 152 | +pub extern crate rand; |
| 153 | +#[cfg(any(test))] |
| 154 | +extern crate rand_core; |
| 155 | +#[cfg(feature = "serde")] |
| 156 | +#[cfg_attr(docsrs, doc(cfg(feature = "serde")))] |
| 157 | +pub extern crate serde; |
| 158 | +#[cfg(all(test, feature = "serde"))] |
| 159 | +extern crate serde_test; |
| 160 | +#[cfg(any(test, feature = "rand"))] |
| 161 | +use rand::Rng; |
| 162 | +#[cfg(any(test, feature = "std"))] |
| 163 | +extern crate core; |
| 164 | +#[cfg(all(test, target_arch = "wasm32"))] |
| 165 | +extern crate wasm_bindgen_test; |
| 166 | +#[cfg(feature = "alloc")] |
| 167 | +extern crate alloc; |
139 | 168 |
|
140 | 169 |
|
141 | 170 | #[macro_use]
|
@@ -163,6 +192,7 @@ use core::{mem, fmt, str};
|
163 | 192 | use ffi::{CPtr, types::AlignedType};
|
164 | 193 |
|
165 | 194 | #[cfg(feature = "global-context-less-secure")]
|
| 195 | +#[cfg_attr(docsrs, doc(cfg(feature = "global-context-less-secure")))] |
166 | 196 | pub use context::global::SECP256K1;
|
167 | 197 |
|
168 | 198 | #[cfg(feature = "bitcoin_hashes")]
|
@@ -196,20 +226,23 @@ pub trait ThirtyTwoByteHash {
|
196 | 226 | }
|
197 | 227 |
|
198 | 228 | #[cfg(feature = "bitcoin_hashes")]
|
| 229 | +#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin_hashes")))] |
199 | 230 | impl ThirtyTwoByteHash for hashes::sha256::Hash {
|
200 | 231 | fn into_32(self) -> [u8; 32] {
|
201 | 232 | self.into_inner()
|
202 | 233 | }
|
203 | 234 | }
|
204 | 235 |
|
205 | 236 | #[cfg(feature = "bitcoin_hashes")]
|
| 237 | +#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin_hashes")))] |
206 | 238 | impl ThirtyTwoByteHash for hashes::sha256d::Hash {
|
207 | 239 | fn into_32(self) -> [u8; 32] {
|
208 | 240 | self.into_inner()
|
209 | 241 | }
|
210 | 242 | }
|
211 | 243 |
|
212 | 244 | #[cfg(feature = "bitcoin_hashes")]
|
| 245 | +#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin_hashes")))] |
213 | 246 | impl<T: hashes::sha256t::Tag> ThirtyTwoByteHash for hashes::sha256t::Hash<T> {
|
214 | 247 | fn into_32(self) -> [u8; 32] {
|
215 | 248 | self.into_inner()
|
@@ -256,6 +289,7 @@ impl Message {
|
256 | 289 | /// assert_eq!(m1, m2);
|
257 | 290 | /// ```
|
258 | 291 | #[cfg(feature = "bitcoin_hashes")]
|
| 292 | + #[cfg_attr(docsrs, doc(cfg(feature = "bitcoin_hashes")))] |
259 | 293 | pub fn from_hashed_data<H: ThirtyTwoByteHash + hashes::Hash>(data: &[u8]) -> Self {
|
260 | 294 | <H as hashes::Hash>::hash(data).into()
|
261 | 295 | }
|
@@ -316,6 +350,7 @@ impl fmt::Display for Error {
|
316 | 350 | }
|
317 | 351 |
|
318 | 352 | #[cfg(feature = "std")]
|
| 353 | +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] |
319 | 354 | impl std::error::Error for Error {}
|
320 | 355 |
|
321 | 356 |
|
@@ -374,6 +409,7 @@ impl<C: Context> Secp256k1<C> {
|
374 | 409 | /// see comment in libsecp256k1 commit d2275795f by Gregory Maxwell. Requires
|
375 | 410 | /// compilation with "rand" feature.
|
376 | 411 | #[cfg(any(test, feature = "rand"))]
|
| 412 | + #[cfg_attr(docsrs, doc(cfg(feature = "rand")))] |
377 | 413 | pub fn randomize<R: Rng + ?Sized>(&mut self, rng: &mut R) {
|
378 | 414 | let mut seed = [0u8; 32];
|
379 | 415 | rng.fill_bytes(&mut seed);
|
@@ -406,6 +442,7 @@ impl<C: Signing> Secp256k1<C> {
|
406 | 442 | /// with the "rand" feature.
|
407 | 443 | #[inline]
|
408 | 444 | #[cfg(any(test, feature = "rand"))]
|
| 445 | + #[cfg_attr(docsrs, doc(cfg(feature = "rand")))] |
409 | 446 | pub fn generate_keypair<R: Rng + ?Sized>(&self, rng: &mut R)
|
410 | 447 | -> (key::SecretKey, key::PublicKey) {
|
411 | 448 | let sk = key::SecretKey::new(rng);
|
|
0 commit comments