Skip to content

Commit b549a6f

Browse files
c410-f3rtomaka
authored andcommitted
Implement Debug for (ed25519|secp256k1)::(Keypair|SecretKey) (libp2p#1285)
1 parent 7eb4165 commit b549a6f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

core/src/identity/ed25519.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use ed25519_dalek as ed25519;
2424
use failure::Fail;
2525
use super::error::DecodingError;
2626
use zeroize::Zeroize;
27+
use core::fmt;
2728

2829
/// An Ed25519 keypair.
2930
pub struct Keypair(ed25519::Keypair);
@@ -66,6 +67,12 @@ impl Keypair {
6667
}
6768
}
6869

70+
impl fmt::Debug for Keypair {
71+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72+
f.debug_struct("Keypair").field("public", &self.0.public).finish()
73+
}
74+
}
75+
6976
impl Clone for Keypair {
7077
fn clone(&self) -> Keypair {
7178
let mut sk_bytes = self.0.secret.to_bytes();
@@ -135,6 +142,12 @@ impl Clone for SecretKey {
135142
}
136143
}
137144

145+
impl fmt::Debug for SecretKey {
146+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
147+
write!(f, "SecretKey")
148+
}
149+
}
150+
138151
impl SecretKey {
139152
/// Generate a new Ed25519 secret key.
140153
pub fn generate() -> SecretKey {

core/src/identity/secp256k1.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use sha2::{Digest as ShaDigestTrait, Sha256};
2626
use secp256k1::{Message, Signature};
2727
use super::error::{DecodingError, SigningError};
2828
use zeroize::Zeroize;
29+
use core::fmt;
2930

3031
/// A Secp256k1 keypair.
3132
#[derive(Clone)]
@@ -51,6 +52,12 @@ impl Keypair {
5152
}
5253
}
5354

55+
impl fmt::Debug for Keypair {
56+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57+
f.debug_struct("Keypair").field("public", &self.public).finish()
58+
}
59+
}
60+
5461
/// Promote a Secp256k1 secret key into a keypair.
5562
impl From<SecretKey> for Keypair {
5663
fn from(secret: SecretKey) -> Keypair {
@@ -70,6 +77,12 @@ impl From<Keypair> for SecretKey {
7077
#[derive(Clone)]
7178
pub struct SecretKey(secp256k1::SecretKey);
7279

80+
impl fmt::Debug for SecretKey {
81+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
82+
write!(f, "SecretKey")
83+
}
84+
}
85+
7386
impl SecretKey {
7487
/// Generate a new Secp256k1 secret key.
7588
pub fn generate() -> SecretKey {

0 commit comments

Comments
 (0)