Skip to content

Commit aa828f0

Browse files
committed
Improve documentation in the key module
We recently patched much of the docs in the `key` module, lets attempt to attain perfection. Improve docs by doing: - Use full stops - Use 100 character column width - Use plural third person tense - Use plural for section headings - Fix any grammar mistakes - Use code ticks and links as appropriate
1 parent 9e46d6f commit aa828f0

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

src/key.rs

+33-26
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl SecretKey {
204204
SecretKey(sk)
205205
}
206206

207-
/// Serialize the secret key as byte value
207+
/// Serializes the secret key as byte value.
208208
#[inline]
209209
pub fn serialize_secret(&self) -> [u8; constants::SECRET_KEY_SIZE] {
210210
self.0
@@ -225,9 +225,12 @@ impl SecretKey {
225225
}
226226

227227
#[inline]
228-
/// Adds one secret key to another, modulo the curve order. WIll
229-
/// return an error if the resulting key would be invalid or if
230-
/// the tweak was not a 32-byte length slice.
228+
/// Adds one secret key to another, modulo the curve order.
229+
///
230+
/// # Errors
231+
///
232+
/// Returns an error if the resulting key would be invalid or if the tweak was not a 32-byte
233+
/// length slice.
231234
pub fn add_assign(
232235
&mut self,
233236
other: &[u8],
@@ -345,7 +348,7 @@ impl PublicKey {
345348
}
346349
}
347350

348-
/// Creates a public key directly from a slice
351+
/// Creates a public key directly from a slice.
349352
#[inline]
350353
pub fn from_slice(data: &[u8]) -> Result<PublicKey, Error> {
351354
if data.is_empty() {return Err(Error::InvalidPublicKey);}
@@ -394,9 +397,8 @@ impl PublicKey {
394397
}
395398

396399
#[inline]
397-
/// Serialize the key as a byte-encoded pair of values. In compressed form
398-
/// the y-coordinate is represented by only a single bit, as x determines
399-
/// it up to one bit.
400+
/// Serializes the key as a byte-encoded pair of values. In compressed form the y-coordinate is
401+
/// represented by only a single bit, as x determines it up to one bit.
400402
pub fn serialize(&self) -> [u8; constants::PUBLIC_KEY_SIZE] {
401403
let mut ret = [0u8; constants::PUBLIC_KEY_SIZE];
402404

@@ -415,7 +417,7 @@ impl PublicKey {
415417
ret
416418
}
417419

418-
/// Serialize the key as a byte-encoded pair of values, in uncompressed form
420+
/// Serializes the key as a byte-encoded pair of values, in uncompressed form.
419421
pub fn serialize_uncompressed(&self) -> [u8; constants::UNCOMPRESSED_PUBLIC_KEY_SIZE] {
420422
let mut ret = [0u8; constants::UNCOMPRESSED_PUBLIC_KEY_SIZE];
421423

@@ -435,8 +437,7 @@ impl PublicKey {
435437
}
436438

437439
#[inline]
438-
/// Negates the pk to the pk `self` in place
439-
/// Will return an error if the pk would be invalid.
440+
/// Negates the public key in place.
440441
pub fn negate_assign<C: Verification>(
441442
&mut self,
442443
secp: &Secp256k1<C>
@@ -448,9 +449,12 @@ impl PublicKey {
448449
}
449450

450451
#[inline]
451-
/// Adds the pk corresponding to `other` to the pk `self` in place
452-
/// Will return an error if the resulting key would be invalid or
453-
/// if the tweak was not a 32-byte length slice.
452+
/// Adds the `other` public key to `self` in place.
453+
///
454+
/// # Errors
455+
///
456+
/// Returns an error if the resulting key would be invalid or if the tweak was not a 32-byte
457+
/// length slice.
454458
pub fn add_exp_assign<C: Verification>(
455459
&mut self,
456460
secp: &Secp256k1<C>,
@@ -469,9 +473,12 @@ impl PublicKey {
469473
}
470474

471475
#[inline]
472-
/// Muliplies the pk `self` in place by the scalar `other`
473-
/// Will return an error if the resulting key would be invalid or
474-
/// if the tweak was not a 32-byte length slice.
476+
/// Muliplies the public key in place by the scalar `other`.
477+
///
478+
/// # Errors
479+
///
480+
/// Returns an error if the resulting key would be invalid or if the tweak was not a 32-byte
481+
/// length slice.
475482
pub fn mul_assign<C: Verification>(
476483
&mut self,
477484
secp: &Secp256k1<C>,
@@ -667,7 +674,7 @@ impl KeyPair {
667674
&mut self.0
668675
}
669676

670-
/// Creates a Schnorr KeyPair directly from generic Secp256k1 secret key.
677+
/// Creates a Schnorr [`KeyPair`] directly from generic Secp256k1 secret key.
671678
///
672679
/// # Panics
673680
///
@@ -689,7 +696,7 @@ impl KeyPair {
689696
}
690697
}
691698

692-
/// Creates a Schnorr KeyPair directly from a secret key slice.
699+
/// Creates a Schnorr [`KeyPair`] directly from a secret key slice.
693700
///
694701
/// # Errors
695702
///
@@ -714,7 +721,7 @@ impl KeyPair {
714721
}
715722
}
716723

717-
/// Creates a Schnorr KeyPair directly from a secret key string
724+
/// Creates a Schnorr [`KeyPair`] directly from a secret key string.
718725
///
719726
/// # Errors
720727
///
@@ -945,13 +952,13 @@ impl str::FromStr for XOnlyPublicKey {
945952
}
946953

947954
impl XOnlyPublicKey {
948-
/// Obtains a raw const pointer suitable for use with FFI functions
955+
/// Obtains a raw const pointer suitable for use with FFI functions.
949956
#[inline]
950957
pub fn as_ptr(&self) -> *const ffi::XOnlyPublicKey {
951958
&self.0
952959
}
953960

954-
/// Obtains a raw mutable pointer suitable for use with FFI functions
961+
/// Obtains a raw mutable pointer suitable for use with FFI functions.
955962
#[inline]
956963
pub fn as_mut_ptr(&mut self) -> *mut ffi::XOnlyPublicKey {
957964
&mut self.0
@@ -974,12 +981,12 @@ impl XOnlyPublicKey {
974981
}
975982
}
976983

977-
/// Creates a Schnorr public key directly from a slice
984+
/// Creates a Schnorr public key directly from a slice.
978985
///
979986
/// # Errors
980987
///
981988
/// Returns [`Error::InvalidPublicKey`] if the length of the data slice is not 32 bytes or the
982-
/// slice does not represent a valid Secp256k1 point x coordinate
989+
/// slice does not represent a valid Secp256k1 point x coordinate.
983990
#[inline]
984991
pub fn from_slice(data: &[u8]) -> Result<XOnlyPublicKey, Error> {
985992
if data.is_empty() || data.len() != constants::SCHNORRSIG_PUBLIC_KEY_SIZE {
@@ -1002,7 +1009,7 @@ impl XOnlyPublicKey {
10021009
}
10031010

10041011
#[inline]
1005-
/// Serialize the key as a byte-encoded x coordinate value (32 bytes).
1012+
/// Serializes the key as a byte-encoded x coordinate value (32 bytes).
10061013
pub fn serialize(&self) -> [u8; constants::SCHNORRSIG_PUBLIC_KEY_SIZE] {
10071014
let mut ret = [0u8; constants::SCHNORRSIG_PUBLIC_KEY_SIZE];
10081015

@@ -1194,7 +1201,7 @@ impl CPtr for XOnlyPublicKey {
11941201
}
11951202
}
11961203

1197-
/// Creates a new Schnorr public key from a FFI x-only public key
1204+
/// Creates a new Schnorr public key from a FFI x-only public key.
11981205
impl From<ffi::XOnlyPublicKey> for XOnlyPublicKey {
11991206
#[inline]
12001207
fn from(pk: ffi::XOnlyPublicKey) -> XOnlyPublicKey {

0 commit comments

Comments
 (0)