Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Jan 22, 2024
1 parent 573a9a2 commit 166bd19
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 54 deletions.
13 changes: 1 addition & 12 deletions profile/src/wallet_kit_common/types/hex_32bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,13 @@ pub struct Hex32Bytes {
bytes: Vec<u8>, // FIXME: We REALLY want `[u8; 32]` - but that does not work in UniFFI land with `uniffi::Record` - so we should write an UniffiCustomTypeConverter for this (yet another one...)
}

impl Default for Hex32Bytes {
fn default() -> Self {
Self::new()
}
}

impl Hex32Bytes {
/// Instantiates a new `Hex32Bytes` from bytes generated by
/// a CSPRNG.
pub fn generate() -> Self {
Hex32Bytes::from_vec(generate_32_bytes())
.expect("Should be able to generate 32 bytes.")
}

/// Just an alias for `Self::generate()`
pub fn new() -> Self {
Self::generate()
}
}

impl Hex32Bytes {
Expand Down Expand Up @@ -257,7 +246,7 @@ mod tests {
let mut set: HashSet<Vec<u8>> = HashSet::new();
let n = 100;
for _ in 0..n {
let bytes = Hex32Bytes::new();
let bytes = Hex32Bytes::generate();
set.insert(bytes.to_vec());
}
assert_eq!(set.len(), n);
Expand Down
14 changes: 1 addition & 13 deletions profile/src/wallet_kit_common/types/keys/ed25519/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ use transaction::signing::ed25519::{
#[debug("{}", self.to_hex())]
pub struct Ed25519PrivateKey(EngineEd25519PrivateKey);

impl Default for Ed25519PrivateKey {
fn default() -> Self {
Self::new()
}
}

impl Ed25519PrivateKey {
/// Generates a new `Ed25519PrivateKey` from random bytes
/// generated by a CSRNG, note that this is typically never
Expand All @@ -26,12 +20,6 @@ impl Ed25519PrivateKey {
Self::from_hex32_bytes(Hex32Bytes::generate())
.expect("Should be able to generate 32 bytes")
}

/// Just an alias for `Self::generate()`, generating a new
/// key from random bytes.
pub fn new() -> Self {
Self::generate()
}
}

impl PartialEq for Ed25519PrivateKey {
Expand Down Expand Up @@ -289,7 +277,7 @@ mod tests {
let mut set: HashSet<Vec<u8>> = HashSet::new();
let n = 100;
for _ in 0..n {
let key = Ed25519PrivateKey::new();
let key = Ed25519PrivateKey::generate();
let bytes = key.to_bytes();
assert_eq!(bytes.len(), 32);
set.insert(bytes);
Expand Down
17 changes: 3 additions & 14 deletions profile/src/wallet_kit_common/types/keys/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl From<Ed25519PrivateKey> for PrivateKey {
/// extern crate profile;
/// use profile::prelude::*;
///
/// let key: PublicKey = Ed25519PrivateKey::new().public_key().into();
/// let key: PublicKey = Ed25519PrivateKey::generate().public_key().into();
/// ```
fn from(value: Ed25519PrivateKey) -> Self {
Self::Ed25519(value)
Expand All @@ -32,25 +32,14 @@ impl From<Secp256k1PrivateKey> for PrivateKey {
/// extern crate profile;
/// use profile::prelude::*;
///
/// let key: PublicKey = Secp256k1PrivateKey::new().public_key().into();
/// let key: PublicKey = Secp256k1PrivateKey::generate().public_key().into();
/// ```
fn from(value: Secp256k1PrivateKey) -> Self {
Self::Secp256k1(value)
}
}

impl Default for PrivateKey {
fn default() -> Self {
Self::new()
}
}

impl PrivateKey {
/// Generates a new `PrivateKey` over Curve25519.
pub fn new() -> Self {
Ed25519PrivateKey::generate().into()
}

/// Calculates the public key of the inner `PrivateKey` and wraps it
/// in the `PublicKey` tagged union.
pub fn public_key(&self) -> PublicKey {
Expand Down Expand Up @@ -137,7 +126,7 @@ mod tests {
let mut set: HashSet<Vec<u8>> = HashSet::new();
let n = 100;
for _ in 0..n {
let key = PrivateKey::new();
let key: PrivateKey = Ed25519PrivateKey::generate().into();
let bytes = key.to_bytes();
assert_eq!(bytes.len(), 32);
set.insert(bytes);
Expand Down
4 changes: 2 additions & 2 deletions profile/src/wallet_kit_common/types/keys/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl From<Ed25519PublicKey> for PublicKey {
/// extern crate profile;
/// use profile::prelude::*;
///
/// let key: PublicKey = Ed25519PrivateKey::new().public_key().into();
/// let key: PublicKey = Ed25519PrivateKey::generate().public_key().into();
/// ```
fn from(value: Ed25519PublicKey) -> Self {
Self::Ed25519 { value }
Expand All @@ -44,7 +44,7 @@ impl From<Secp256k1PublicKey> for PublicKey {
/// extern crate profile;
/// use profile::prelude::*;
///
/// let key: PublicKey = Secp256k1PrivateKey::new().public_key().into();
/// let key: PublicKey = Secp256k1PrivateKey::generate().public_key().into();
/// ```
fn from(value: Secp256k1PublicKey) -> Self {
Self::Secp256k1 { value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ use transaction::signing::secp256k1::{
#[debug("{}", self.to_hex())]
pub struct Secp256k1PrivateKey(EngineSecp256k1PrivateKey);

impl Default for Secp256k1PrivateKey {
fn default() -> Self {
Self::new()
}
}

impl Secp256k1PrivateKey {
/// Generates a new `Secp256k1PrivateKey` from random bytes
/// generated by a CSRNG, note that this is typically never
Expand All @@ -26,12 +20,6 @@ impl Secp256k1PrivateKey {
Self::from_hex32_bytes(Hex32Bytes::generate())
.expect("Should be able to generate 32 bytes")
}

/// Just an alias for `Self::generate()`, generating a new
/// key from random bytes.
pub fn new() -> Self {
Self::generate()
}
}

impl PartialEq for Secp256k1PrivateKey {
Expand Down Expand Up @@ -306,7 +294,7 @@ mod tests {
let mut set: HashSet<Vec<u8>> = HashSet::new();
let n = 100;
for _ in 0..n {
let key = Secp256k1PrivateKey::new();
let key = Secp256k1PrivateKey::generate();
let bytes = key.to_bytes();
assert_eq!(bytes.len(), 32);
set.insert(bytes);
Expand Down

0 comments on commit 166bd19

Please sign in to comment.