diff options
author | Azul <azul@riseup.net> | 2020-11-17 07:26:59 +0100 |
---|---|---|
committer | Azul <azul@riseup.net> | 2020-11-17 07:26:59 +0100 |
commit | 713971ed58a9234ee8c1f420ec4627ea277aef69 (patch) | |
tree | 896df1b1a0c52e264bdc75f29ae2a1599670a4c7 | |
parent | 6bf28fe92ef8dfd363cb856a3a8702e78b652df9 (diff) |
openpgp: seal crypto::hash::Hash traitazul/seal-hash-trait
refs: #538
-rw-r--r-- | openpgp/src/crypto/hash.rs | 11 | ||||
-rw-r--r-- | openpgp/src/crypto/mpi.rs | 6 |
2 files changed, 16 insertions, 1 deletions
diff --git a/openpgp/src/crypto/hash.rs b/openpgp/src/crypto/hash.rs index 5517d205..49123623 100644 --- a/openpgp/src/crypto/hash.rs +++ b/openpgp/src/crypto/hash.rs @@ -21,6 +21,7 @@ use crate::packet::key::Key4; use crate::packet::Signature; use crate::packet::signature::{self, Signature4}; use crate::Result; +use crate::seal; use crate::types::Timestamp; use std::fs::{File, OpenOptions}; @@ -235,11 +236,12 @@ impl Digest for HashDumper { /// functions] for how to hash compounds like (Key,UserID)-bindings. /// /// [`Signature`'s hashing functions]: ../../packet/enum.Signature.html#hashing-functions -pub trait Hash { +pub trait Hash: seal::Sealed { /// Updates the given hash with this object. fn hash(&self, hash: &mut Context); } +impl seal::Sealed for UserID {} impl Hash for UserID { fn hash(&self, hash: &mut Context) { let len = self.value().len() as u32; @@ -253,6 +255,7 @@ impl Hash for UserID { } } +impl seal::Sealed for UserAttribute {} impl Hash for UserAttribute { fn hash(&self, hash: &mut Context) { let len = self.value().len() as u32; @@ -266,6 +269,9 @@ impl Hash for UserAttribute { } } +impl<P, R> seal::Sealed for Key4<P, R> + where P: key::KeyParts, + R: key::KeyRole, {} impl<P, R> Hash for Key4<P, R> where P: key::KeyParts, R: key::KeyRole, @@ -305,6 +311,7 @@ impl<P, R> Hash for Key4<P, R> } } +impl seal::Sealed for Signature {} impl Hash for Signature { fn hash(&self, hash: &mut Context) { match self { @@ -313,12 +320,14 @@ impl Hash for Signature { } } +impl seal::Sealed for Signature4 {} impl Hash for Signature4 { fn hash(&self, hash: &mut Context) { self.fields.hash(hash); } } +impl seal::Sealed for signature::SignatureFields {} impl Hash for signature::SignatureFields { fn hash(&self, hash: &mut Context) { use crate::serialize::MarshalInto; diff --git a/openpgp/src/crypto/mpi.rs b/openpgp/src/crypto/mpi.rs index 8f9cfb2a..e2b8373d 100644 --- a/openpgp/src/crypto/mpi.rs +++ b/openpgp/src/crypto/mpi.rs @@ -31,6 +31,7 @@ use crate::types::{ }; use crate::crypto::hash::{self, Hash}; use crate::crypto::mem::{secure_cmp, Protected}; +use crate::seal; use crate::serialize::Marshal; use crate::Error; @@ -236,6 +237,7 @@ impl fmt::Debug for MPI { } } +impl seal::Sealed for MPI {} impl Hash for MPI { fn hash(&self, hash: &mut hash::Context) { let len = self.bits() as u16; @@ -544,6 +546,7 @@ impl PublicKey { } } +impl seal::Sealed for PublicKey {} impl Hash for PublicKey { fn hash(&self, hash: &mut hash::Context) { self.serialize(hash).expect("hashing does not fail") @@ -805,6 +808,7 @@ impl SecretKeyMaterial { } } +impl seal::Sealed for SecretKeyMaterial {} impl Hash for SecretKeyMaterial { fn hash(&self, hash: &mut hash::Context) { self.serialize(hash).expect("hashing does not fail") @@ -929,6 +933,7 @@ impl Ciphertext { } } +impl seal::Sealed for Ciphertext {} impl Hash for Ciphertext { fn hash(&self, hash: &mut hash::Context) { self.serialize(hash).expect("hashing does not fail") @@ -1020,6 +1025,7 @@ pub enum Signature { }, } +impl seal::Sealed for Signature {} impl Hash for Signature { fn hash(&self, hash: &mut hash::Context) { self.serialize(hash).expect("hashing does not fail") |