diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-12-20 18:04:46 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-12-27 16:29:22 +0100 |
commit | f69cf9bb74ad5ee7002ac1e84caaad635b9b52b3 (patch) | |
tree | 129afc038dd8cc77530c10198b3611948e35fae9 /openpgp | |
parent | bbd0b9e19a42b8ee634bacc55e96b9d29cf1e034 (diff) |
openpgp: Time-constant eq for Passwords, SessionKeys.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/crypto/mod.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/openpgp/src/crypto/mod.rs b/openpgp/src/crypto/mod.rs index 9da5a8d9..d3deb2e1 100644 --- a/openpgp/src/crypto/mod.rs +++ b/openpgp/src/crypto/mod.rs @@ -22,9 +22,15 @@ pub(crate) mod symmetric; /// Holds a session key. /// /// The session key is cleared when dropped. -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, Eq)] pub struct SessionKey(Box<[u8]>); +impl PartialEq for SessionKey { + fn eq(&self, other: &Self) -> bool { + secure_cmp(&self.0, &other.0) == Ordering::Equal + } +} + impl SessionKey { /// Creates a new session key. pub fn new(rng: &mut Yarrow, size: usize) -> Self { @@ -75,9 +81,15 @@ impl fmt::Debug for SessionKey { /// Holds a password. /// /// The password is cleared when dropped. -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, Eq)] pub struct Password(Box<[u8]>); +impl PartialEq for Password { + fn eq(&self, other: &Self) -> bool { + secure_cmp(&self.0, &other.0) == Ordering::Equal + } +} + impl Deref for Password { type Target = [u8]; |