Implement Debug for (ed25519|secp256k1)::(Keypair|SecretKey) (#1285)

This commit is contained in:
Caio
2019-10-28 09:46:08 -03:00
committed by Pierre Krieger
parent 9e314a123b
commit 54ee836409
2 changed files with 26 additions and 0 deletions

View File

@ -24,6 +24,7 @@ use ed25519_dalek as ed25519;
use failure::Fail; use failure::Fail;
use super::error::DecodingError; use super::error::DecodingError;
use zeroize::Zeroize; use zeroize::Zeroize;
use core::fmt;
/// An Ed25519 keypair. /// An Ed25519 keypair.
pub struct Keypair(ed25519::Keypair); pub struct Keypair(ed25519::Keypair);
@ -66,6 +67,12 @@ impl Keypair {
} }
} }
impl fmt::Debug for Keypair {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Keypair").field("public", &self.0.public).finish()
}
}
impl Clone for Keypair { impl Clone for Keypair {
fn clone(&self) -> Keypair { fn clone(&self) -> Keypair {
let mut sk_bytes = self.0.secret.to_bytes(); let mut sk_bytes = self.0.secret.to_bytes();
@ -135,6 +142,12 @@ impl Clone for SecretKey {
} }
} }
impl fmt::Debug for SecretKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SecretKey")
}
}
impl SecretKey { impl SecretKey {
/// Generate a new Ed25519 secret key. /// Generate a new Ed25519 secret key.
pub fn generate() -> SecretKey { pub fn generate() -> SecretKey {

View File

@ -26,6 +26,7 @@ use sha2::{Digest as ShaDigestTrait, Sha256};
use secp256k1::{Message, Signature}; use secp256k1::{Message, Signature};
use super::error::{DecodingError, SigningError}; use super::error::{DecodingError, SigningError};
use zeroize::Zeroize; use zeroize::Zeroize;
use core::fmt;
/// A Secp256k1 keypair. /// A Secp256k1 keypair.
#[derive(Clone)] #[derive(Clone)]
@ -51,6 +52,12 @@ impl Keypair {
} }
} }
impl fmt::Debug for Keypair {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Keypair").field("public", &self.public).finish()
}
}
/// Promote a Secp256k1 secret key into a keypair. /// Promote a Secp256k1 secret key into a keypair.
impl From<SecretKey> for Keypair { impl From<SecretKey> for Keypair {
fn from(secret: SecretKey) -> Keypair { fn from(secret: SecretKey) -> Keypair {
@ -70,6 +77,12 @@ impl From<Keypair> for SecretKey {
#[derive(Clone)] #[derive(Clone)]
pub struct SecretKey(secp256k1::SecretKey); pub struct SecretKey(secp256k1::SecretKey);
impl fmt::Debug for SecretKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SecretKey")
}
}
impl SecretKey { impl SecretKey {
/// Generate a new Secp256k1 secret key. /// Generate a new Secp256k1 secret key.
pub fn generate() -> SecretKey { pub fn generate() -> SecretKey {