Skip to content

Commit

Permalink
Rename serialize_secret -> to_bytes
Browse files Browse the repository at this point in the history
The `serialize_secret` method is a conversion method, we do not do any
special serialisation logic. Using the more idiomatic `to_bytes` fully
describes the method.

Rename `serialize_secret` to be `to_bytes`.
  • Loading branch information
tcharding committed Feb 22, 2022
1 parent 0165f51 commit d54f7f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ impl SecretKey {
SecretKey(sk)
}

/// Serializes the secret key as byte value.
/// Gets the secret key as a byte value.
#[inline]
pub fn serialize_secret(&self) -> [u8; constants::SECRET_KEY_SIZE] {
pub fn to_bytes(&self) -> [u8; constants::SECRET_KEY_SIZE] {
self.0
}

Expand Down Expand Up @@ -809,9 +809,9 @@ impl KeyPair {
KeyPair::new(SECP256K1, rng)
}

/// Serializes the key pair as a secret key byte value.
/// Gets the secret bytes for this key pair.
#[inline]
pub fn serialize_secret(&self) -> [u8; constants::SECRET_KEY_SIZE] {
pub fn to_bytes(&self) -> [u8; constants::SECRET_KEY_SIZE] {
*SecretKey::from_keypair(self).as_ref()
}

Expand Down Expand Up @@ -926,7 +926,7 @@ impl ::serde::Serialize for KeyPair {
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
if s.is_human_readable() {
let mut buf = [0u8; constants::SECRET_KEY_SIZE * 2];
s.serialize_str(::to_hex(&self.serialize_secret(), &mut buf)
s.serialize_str(::to_hex(&self.to_bytes(), &mut buf)
.expect("fixed-size hex serialization"))
} else {
s.serialize_bytes(&self.0[..])
Expand Down
8 changes: 4 additions & 4 deletions src/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ macro_rules! impl_display_secret {

hasher.write(DEBUG_HASH_TAG);
hasher.write(DEBUG_HASH_TAG);
hasher.write(&self.serialize_secret());
hasher.write(&self.to_bytes());
let hash = hasher.finish();

f.debug_tuple(stringify!($thing))
Expand All @@ -55,7 +55,7 @@ macro_rules! impl_display_secret {
let tag_hash = sha256::Hash::hash(tag.as_bytes());
engine.input(&tag_hash[..]);
engine.input(&tag_hash[..]);
engine.input(&self.serialize_secret());
engine.input(&self.to_bytes());
let hash = sha256::Hash::from_engine(engine);

f.debug_tuple(stringify!($thing))
Expand Down Expand Up @@ -139,7 +139,7 @@ impl SecretKey {
/// ```
#[inline]
pub fn display_secret(&self) -> DisplaySecret {
DisplaySecret { secret: self.serialize_secret() }
DisplaySecret { secret: self.to_bytes() }
}
}

Expand Down Expand Up @@ -180,6 +180,6 @@ impl KeyPair {
/// ```
#[inline]
pub fn display_secret(&self) -> DisplaySecret {
DisplaySecret { secret: self.serialize_secret() }
DisplaySecret { secret: self.to_bytes() }
}
}

0 comments on commit d54f7f1

Please sign in to comment.