summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/mod.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-08-07 17:22:20 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-08-10 11:49:43 +0200
commita4176e5369f7de866f2e6473e68e7f6ec1f1aee8 (patch)
tree40d4832c87bb13be7f1f6e99b2aef0d11f691193 /openpgp/src/crypto/mod.rs
parenta5d6f12eb8ca200478f1be2531d2ee122cc8b5f9 (diff)
openpgp: Correctly handle text signatures when verifying.
- Text signatures require normalizing the line endings to "\r\n" before the text is hashed. This change implements this for the consumption of signatures. The next commit will handle the production of such signatures. - See #530.
Diffstat (limited to 'openpgp/src/crypto/mod.rs')
-rw-r--r--openpgp/src/crypto/mod.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/openpgp/src/crypto/mod.rs b/openpgp/src/crypto/mod.rs
index cbf23751..5deba504 100644
--- a/openpgp/src/crypto/mod.rs
+++ b/openpgp/src/crypto/mod.rs
@@ -27,6 +27,7 @@ use buffered_reader::BufferedReader;
use crate::types::HashAlgorithm;
use crate::Result;
+use crate::parse::HashingMode;
pub(crate) mod aead;
mod asymmetric;
@@ -218,8 +219,8 @@ impl Password {
/// convenient method, see [`DetachedVerifier`].
///
/// [`DetachedVerifier`]: ../parse/stream/struct.DetachedVerifier.html
-pub fn hash_reader<R: Read>(reader: R, algos: &[HashAlgorithm])
- -> Result<Vec<hash::Context>>
+pub fn hash_reader<R: Read>(reader: R, algos: &[HashingMode<HashAlgorithm>])
+ -> Result<Vec<HashingMode<hash::Context>>>
{
let reader
= buffered_reader::Generic::with_cookie(
@@ -233,8 +234,9 @@ pub fn hash_reader<R: Read>(reader: R, algos: &[HashAlgorithm])
/// 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>>
+pub(crate) fn hash_buffered_reader<R>(reader: R,
+ algos: &[HashingMode<HashAlgorithm>])
+ -> Result<Vec<HashingMode<hash::Context>>>
where R: BufferedReader<crate::parse::Cookie>,
{
use std::mem;
@@ -266,10 +268,13 @@ fn hash_reader_test() {
let result =
hash_reader(std::io::Cursor::new(crate::tests::manifesto()),
- &expected.keys().cloned().collect::<Vec<HashAlgorithm>>())
+ &expected.keys().cloned()
+ .map(|algo| HashingMode::Binary(algo)).
+ collect::<Vec<_>>())
.unwrap();
- for mut hash in result.into_iter() {
+ for mut mode in result.into_iter() {
+ let hash = mode.as_mut();
let algo = hash.algo();
let mut digest = vec![0u8; hash.digest_size()];
hash.digest(&mut digest);