diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-01-03 12:56:23 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-01-03 12:57:36 +0100 |
commit | fe2f0ab072acd0ba81ee23a91cba3d689bb8334b (patch) | |
tree | 4d0c5d62eb3819ad75c063c848382219dd891cfb | |
parent | 7fd9f46fcc4ffb863b02e493fcbe49295564b741 (diff) |
openpgp: Fix PartialEq, Hash for mem::Encrypted.
- Fixes PartialEq for Password.
- See #92.
-rw-r--r-- | openpgp/src/crypto/mem.rs | 17 | ||||
-rw-r--r-- | openpgp/src/packet/key/mod.rs | 16 |
2 files changed, 17 insertions, 16 deletions
diff --git a/openpgp/src/crypto/mem.rs b/openpgp/src/crypto/mem.rs index 4dfe5457..1bfec9a9 100644 --- a/openpgp/src/crypto/mem.rs +++ b/openpgp/src/crypto/mem.rs @@ -121,12 +121,27 @@ impl fmt::Debug for Protected { /// This kind of protection was pioneered by OpenSSH. The commit /// adding it can be found /// [here](https://marc.info/?l=openbsd-cvs&m=156109087822676). -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Debug)] pub struct Encrypted { ciphertext: Protected, iv: Protected, } +impl PartialEq for Encrypted { + fn eq(&self, other: &Self) -> bool { + // Protected::eq is time-constant. + self.map(|a| other.map(|b| a == b)) + } +} + +impl Eq for Encrypted {} + +impl Hash for Encrypted { + fn hash<H: Hasher>(&self, state: &mut H) { + self.map(|k| Hash::hash(k, state)); + } +} + /// The number of pages containing random bytes to derive the prekey /// from. const ENCRYPTED_MEMORY_PREKEY_PAGES: usize = 4; diff --git a/openpgp/src/packet/key/mod.rs b/openpgp/src/packet/key/mod.rs index 4d2ae31a..03b81eef 100644 --- a/openpgp/src/packet/key/mod.rs +++ b/openpgp/src/packet/key/mod.rs @@ -1171,26 +1171,12 @@ impl SecretKeyMaterial { /// demand. See [`crypto::mem::Encrypted`] for details. /// /// [`crypto::mem::Encrypted`]: ../../crypto/mem/struct.Encrypted.html -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Unencrypted { /// MPIs of the secret key. mpis: mem::Encrypted, } -impl PartialEq for Unencrypted { - fn eq(&self, other: &Self) -> bool { - self.map(|a| other.map(|b| a == b)) - } -} - -impl Eq for Unencrypted {} - -impl std::hash::Hash for Unencrypted { - fn hash<H: std::hash::Hasher>(&self, state: &mut H) { - self.map(|k| std::hash::Hash::hash(k, state)); - } -} - impl From<mpis::SecretKeyMaterial> for Unencrypted { fn from(mpis: mpis::SecretKeyMaterial) -> Self { use crate::serialize::Serialize; |