Skip to content

Commit ea6ffc3

Browse files
authored
Implement Debug and Eq for ExpandedSecretKey (#748)
1 parent 08d7176 commit ea6ffc3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

ed25519-dalek/src/hazmat.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
// defined.
1414
#![allow(dead_code)]
1515

16+
use core::fmt::Debug;
17+
1618
use crate::{InternalError, SignatureError};
1719

1820
use curve25519_dalek::scalar::{clamp_integer, Scalar};
1921

22+
use subtle::{Choice, ConstantTimeEq};
2023
#[cfg(feature = "zeroize")]
2124
use zeroize::{Zeroize, ZeroizeOnDrop};
2225

@@ -41,6 +44,26 @@ pub struct ExpandedSecretKey {
4144
pub hash_prefix: [u8; 32],
4245
}
4346

47+
impl Debug for ExpandedSecretKey {
48+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
49+
f.debug_struct("ExpandedSecretKey").finish_non_exhaustive() // avoids printing secrets
50+
}
51+
}
52+
53+
impl ConstantTimeEq for ExpandedSecretKey {
54+
fn ct_eq(&self, other: &Self) -> Choice {
55+
self.scalar.ct_eq(&other.scalar) & self.hash_prefix.ct_eq(&other.hash_prefix)
56+
}
57+
}
58+
59+
impl PartialEq for ExpandedSecretKey {
60+
fn eq(&self, other: &Self) -> bool {
61+
self.ct_eq(other).into()
62+
}
63+
}
64+
65+
impl Eq for ExpandedSecretKey {}
66+
4467
#[cfg(feature = "zeroize")]
4568
impl Drop for ExpandedSecretKey {
4669
fn drop(&mut self) {

0 commit comments

Comments
 (0)