Skip to content

Commit

Permalink
Implement Debug for (ed25519|secp256k1)::(Keypair|SecretKey)
Browse files Browse the repository at this point in the history
  • Loading branch information
c410-f3r committed Oct 24, 2019
1 parent 206e4e7 commit b600c82
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions core/src/identity/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

//! Ed25519 keys.

use core::fmt;
use ed25519_dalek as ed25519;
use failure::Fail;
use super::error::DecodingError;
Expand Down Expand Up @@ -66,6 +67,16 @@ impl Keypair {
}
}

impl fmt::Debug for Keypair {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Keypair( ed25519::Keypair {{ secret: \"Secret Key\", public: \"{:?}\" }} )",
&self.0.public
)
}
}

impl Clone for Keypair {
fn clone(&self) -> Keypair {
let mut sk_bytes = self.0.secret.to_bytes();
Expand Down Expand Up @@ -135,6 +146,12 @@ impl Clone for SecretKey {
}
}

impl fmt::Debug for SecretKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Secret Key")
}
}

impl SecretKey {
/// Generate a new Ed25519 secret key.
pub fn generate() -> SecretKey {
Expand Down
13 changes: 13 additions & 0 deletions core/src/identity/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use sha2::{Digest as ShaDigestTrait, Sha256};
use secp256k1::{Message, Signature};
use super::error::{DecodingError, SigningError};
use zeroize::Zeroize;
use core::fmt;

/// A Secp256k1 keypair.
#[derive(Clone)]
Expand All @@ -51,6 +52,12 @@ impl Keypair {
}
}

impl fmt::Debug for Keypair {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Keypair {{ secret: \"Secret Key\", public: \"{:?}\" }}", &self.public)
}
}

/// Promote a Secp256k1 secret key into a keypair.
impl From<SecretKey> for Keypair {
fn from(secret: SecretKey) -> Keypair {
Expand All @@ -70,6 +77,12 @@ impl From<Keypair> for SecretKey {
#[derive(Clone)]
pub struct SecretKey(secp256k1::SecretKey);

impl fmt::Debug for SecretKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Secret Key")
}
}

impl SecretKey {
/// Generate a new Secp256k1 secret key.
pub fn generate() -> SecretKey {
Expand Down

0 comments on commit b600c82

Please sign in to comment.