diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-11-17 15:20:48 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-12-07 16:29:46 +0100 |
commit | 3b88cd1725bdded57c2ff845db5d471d2da63e6a (patch) | |
tree | 1dee880b1e4666db41d1b98d5edd54cd7bc5b130 | |
parent | f444c789247fb7d96a825b8f66fde6a44c576584 (diff) |
openpgp: Require Write for impl Digest.
-rw-r--r-- | openpgp/src/crypto/backend/cng/hash.rs | 12 | ||||
-rw-r--r-- | openpgp/src/crypto/hash.rs | 12 |
2 files changed, 23 insertions, 1 deletions
diff --git a/openpgp/src/crypto/backend/cng/hash.rs b/openpgp/src/crypto/backend/cng/hash.rs index 1f58d4cc..8d3bbb0f 100644 --- a/openpgp/src/crypto/backend/cng/hash.rs +++ b/openpgp/src/crypto/backend/cng/hash.rs @@ -1,4 +1,5 @@ use core::convert::{TryFrom, TryInto}; +use std::io; use std::sync::Mutex; use crate::crypto::hash::Digest; @@ -61,6 +62,17 @@ impl Digest for Hash { } } +impl io::Write for Hash { + fn write(&mut self, buf: &[u8]) -> io::Result<usize> { + self.update(buf); + Ok(buf.len()) + } + fn flush(&mut self) -> io::Result<()> { + // Do nothing. + Ok(()) + } +} + impl TryFrom<HashAlgorithm> for cng::HashAlgorithmId { type Error = Error; diff --git a/openpgp/src/crypto/hash.rs b/openpgp/src/crypto/hash.rs index 410d9eae..27641429 100644 --- a/openpgp/src/crypto/hash.rs +++ b/openpgp/src/crypto/hash.rs @@ -31,7 +31,7 @@ use std::io::{self, Write}; const DUMP_HASHED_VALUES: Option<&str> = None; /// Hasher capable of calculating a digest for the input byte stream. -pub(crate) trait Digest: DynClone + Send + Sync { +pub(crate) trait Digest: DynClone + Write + Send + Sync { /// Returns the algorithm. fn algo(&self) -> HashAlgorithm; @@ -229,6 +229,16 @@ impl Digest for HashDumper { } } +impl io::Write for HashDumper { + fn write(&mut self, buf: &[u8]) -> io::Result<usize> { + self.hasher.write(buf) + } + + fn flush(&mut self) -> io::Result<()> { + self.hasher.flush() + } +} + /// Hashes OpenPGP packets and related types. /// /// Some OpenPGP data structures need to be hashed to be covered by |