Skip to content

Commit 78a86f1

Browse files
authored
ed25519-dalek: hide secret in SigningKey's Debug impl (dalek-cryptography#592)
Uses `finish_non_exhaustive` in lieu of printing the `secret_key` component of a `SigningKey`, only showing the corresponding `verifying_key` field which can be used to identify the public key. Closes dalek-cryptography#591
1 parent f4cd43f commit 78a86f1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ed25519-dalek/src/signing.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
//! ed25519 signing keys.
1111
12+
use core::fmt::Debug;
13+
1214
#[cfg(feature = "pkcs8")]
1315
use ed25519::pkcs8;
1416

@@ -58,7 +60,7 @@ pub type SecretKey = [u8; SECRET_KEY_LENGTH];
5860
// Invariant: `verifying_key` is always the public key of
5961
// `secret_key`. This prevents the signing function oracle attack
6062
// described in https://github.com/MystenLabs/ed25519-unsafe-libs
61-
#[derive(Clone, Debug)]
63+
#[derive(Clone)]
6264
pub struct SigningKey {
6365
/// The secret half of this signing key.
6466
pub(crate) secret_key: SecretKey,
@@ -507,6 +509,14 @@ impl AsRef<VerifyingKey> for SigningKey {
507509
}
508510
}
509511

512+
impl Debug for SigningKey {
513+
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
514+
f.debug_struct("SigningKey")
515+
.field("verifying_key", &self.verifying_key)
516+
.finish_non_exhaustive() // avoids printing `secret_key`
517+
}
518+
}
519+
510520
impl KeypairRef for SigningKey {
511521
type VerifyingKey = VerifyingKey;
512522
}

0 commit comments

Comments
 (0)