Skip to content

Commit 4ff168b

Browse files
committed
Merge #512: Improve docs crate wide
ec47198 Remove ONE_KEY (Tobin C. Harding) d546c16 Remove cfg docs feature requirements (Tobin C. Harding) 5a7cede doc: Fix preallocated memory grammar (Tobin C. Harding) Pull request description: Read over and improve various parts of the crate documentation. Note this is an API breaking PR because it removes the public `ONE_KEY` type that we exposed when writing the docs for the `secret` module, exposing this type was, in my opinion, a mistake. ACKs for top commit: apoelstra: ACK ec47198 Tree-SHA512: cf8573e58c9498093b0df3f240501d3ad0a9d65e07d2f7c3a9e4116bac6ba366d3d41ac695f4e79010597124512a43b32b4ecb02b08d81226c527d5f77a1a541
2 parents 5a54694 + ec47198 commit 4ff168b

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

src/context.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,19 @@ pub trait Signing: Context {}
7676
/// Marker trait for indicating that an instance of `Secp256k1` can be used for verification.
7777
pub trait Verification: Context {}
7878

79-
/// Represents the set of capabilities needed for signing with a user preallocated memory.
79+
/// Represents the set of capabilities needed for signing (preallocated memory).
8080
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
8181
pub struct SignOnlyPreallocated<'buf> {
8282
phantom: PhantomData<&'buf ()>,
8383
}
8484

85-
/// Represents the set of capabilities needed for verification with a user preallocated memory.
85+
/// Represents the set of capabilities needed for verification (preallocated memory).
8686
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
8787
pub struct VerifyOnlyPreallocated<'buf> {
8888
phantom: PhantomData<&'buf ()>,
8989
}
9090

91-
/// Represents the set of all capabilities with a user preallocated memory.
91+
/// Represents the set of all capabilities (preallocated memory).
9292
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
9393
pub struct AllPreallocated<'buf> {
9494
phantom: PhantomData<&'buf ()>,
@@ -121,17 +121,14 @@ mod alloc_only {
121121
const ALIGN_TO: usize = core::mem::align_of::<AlignedType>();
122122

123123
/// Represents the set of capabilities needed for signing.
124-
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
125124
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
126125
pub enum SignOnly {}
127126

128127
/// Represents the set of capabilities needed for verification.
129-
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
130128
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
131129
pub enum VerifyOnly {}
132130

133131
/// Represents the set of all capabilities.
134-
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
135132
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
136133
pub enum All {}
137134

@@ -301,7 +298,7 @@ unsafe impl<'buf> Context for AllPreallocated<'buf> {
301298
}
302299

303300
impl<'buf, C: Context + 'buf> Secp256k1<C> {
304-
/// Lets you create a context with preallocated buffer in a generic manner(sign/verify/all)
301+
/// Lets you create a context with a preallocated buffer in a generic manner(sign/verify/all).
305302
pub fn preallocated_gen_new(buf: &'buf mut [AlignedType]) -> Result<Secp256k1<C>, Error> {
306303
#[cfg(target_arch = "wasm32")]
307304
ffi::types::sanity_checks_for_wasm();

src/key.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ impl str::FromStr for SecretKey {
7474
}
7575
}
7676

77-
/// The number 1 encoded as a secret key.
78-
pub const ONE_KEY: SecretKey = SecretKey(constants::ONE);
79-
8077
/// A Secp256k1 public key, used for verification of signatures.
8178
///
8279
/// # Serde support

src/secret.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ impl SecretKey {
118118
///
119119
/// ```
120120
/// # #[cfg(feature = "std")] {
121-
/// let key = secp256k1::ONE_KEY;
121+
/// # use std::str::FromStr;
122+
/// use secp256k1::SecretKey;
123+
/// let key = SecretKey::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap();
122124
///
123125
/// // Normal debug hides value (`Display` is not implemented for `SecretKey`).
124126
/// // E.g., `format!("{:?}", key)` prints "SecretKey(#2518682f7819fb2d)".
@@ -152,12 +154,11 @@ impl KeyPair {
152154
///
153155
/// ```
154156
/// # #[cfg(feature = "std")] {
155-
/// use secp256k1::ONE_KEY;
156-
/// use secp256k1::KeyPair;
157-
/// use secp256k1::Secp256k1;
157+
/// # use std::str::FromStr;
158+
/// use secp256k1::{KeyPair, Secp256k1, SecretKey};
158159
///
159160
/// let secp = Secp256k1::new();
160-
/// let key = ONE_KEY;
161+
/// let key = SecretKey::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap();
161162
/// let key = KeyPair::from_secret_key(&secp, &key);
162163
/// // Here we explicitly display the secret value:
163164
/// assert_eq!(
@@ -190,7 +191,7 @@ impl SharedSecret {
190191
/// # #[cfg(not(fuzzing))]
191192
/// # #[cfg(feature = "std")] {
192193
/// # use std::str::FromStr;
193-
/// # use secp256k1::{SecretKey, PublicKey};
194+
/// use secp256k1::{SecretKey, PublicKey};
194195
/// use secp256k1::ecdh::SharedSecret;
195196
///
196197
/// # let pk = PublicKey::from_slice(&[3, 23, 183, 225, 206, 31, 159, 148, 195, 42, 67, 115, 146, 41, 248, 140, 11, 3, 51, 41, 111, 180, 110, 143, 114, 134, 88, 73, 198, 174, 52, 184, 78]).expect("hard coded slice should parse correctly");

0 commit comments

Comments
 (0)