summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/mod.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-03-25 15:18:28 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-03-25 15:18:28 +0100
commit90e8dc67395797b67d51f1b23f4b74f84de0fef2 (patch)
tree25a924c29c658dcb4ca26f207a4d42d3c82158bd /openpgp/src/crypto/mod.rs
parentff2ff2e3f78bd75a8e67f9d25516756ffb3708ab (diff)
openpgp: Provide crypto::hash_buffered_reader.
Diffstat (limited to 'openpgp/src/crypto/mod.rs')
-rw-r--r--openpgp/src/crypto/mod.rs23
1 files changed, 17 insertions, 6 deletions
diff --git a/openpgp/src/crypto/mod.rs b/openpgp/src/crypto/mod.rs
index d1b9f540..3cb029dd 100644
--- a/openpgp/src/crypto/mod.rs
+++ b/openpgp/src/crypto/mod.rs
@@ -4,6 +4,7 @@ use std::io::Read;
use std::ops::{Deref, DerefMut};
use std::fmt;
+use buffered_reader::BufferedReader;
use nettle::random::{Random, Yarrow};
use crate::types::HashAlgorithm;
@@ -172,17 +173,27 @@ impl Password {
pub fn hash_reader<R: Read>(reader: R, algos: &[HashAlgorithm])
-> Result<Vec<hash::Context>>
{
+ let reader
+ = buffered_reader::Generic::with_cookie(
+ reader, None, Default::default());
+ hash_buffered_reader(reader, algos)
+}
+
+/// Hashes the given buffered reader.
+///
+/// This can be used to verify detached signatures. For a more
+/// convenient method, see [`DetachedVerifier`].
+///
+/// [`DetachedVerifier`]: ../parse/stream/struct.DetachedVerifier.html
+pub(crate) fn hash_buffered_reader<R>(reader: R, algos: &[HashAlgorithm])
+ -> Result<Vec<hash::Context>>
+ where R: BufferedReader<crate::parse::Cookie>,
+{
use std::mem;
use crate::parse::HashedReader;
use crate::parse::HashesFor;
- use buffered_reader::BufferedReader;
-
- let reader
- = buffered_reader::Generic::with_cookie(
- reader, None, Default::default());
-
let mut reader
= HashedReader::new(reader, HashesFor::Signature, algos.to_vec());