diff options
-rw-r--r-- | openpgp/src/packet/signature/mod.rs | 20 | ||||
-rw-r--r-- | openpgp/src/parse/parse.rs | 10 | ||||
-rw-r--r-- | sqv/src/sqv.rs | 3 |
3 files changed, 16 insertions, 17 deletions
diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs index 2978c834..5da9117a 100644 --- a/openpgp/src/packet/signature/mod.rs +++ b/openpgp/src/packet/signature/mod.rs @@ -274,7 +274,7 @@ impl Builder { fields: self, hash_prefix: [digest[0], digest[1]], mpis: mpis, - computed_hash: Some((algo, digest)), + computed_hash: Some(digest), level: 0, }.into()) } @@ -333,7 +333,7 @@ pub struct Signature4 { /// When used in conjunction with a one-pass signature, this is the /// hash computed over the enclosed message. - computed_hash: Option<(HashAlgorithm, Vec<u8>)>, + computed_hash: Option<Vec<u8>>, /// Signature level. /// @@ -366,8 +366,8 @@ impl fmt::Debug for Signature4 { .field("hash_prefix", &crate::fmt::to_hex(&self.hash_prefix, false)) .field("computed_hash", - &if let Some((algo, ref hash)) = self.computed_hash { - Some((algo, crate::fmt::to_hex(&hash[..], false))) + &if let Some(ref hash) = self.computed_hash { + Some(crate::fmt::to_hex(&hash[..], false)) } else { None }) @@ -460,13 +460,13 @@ impl Signature4 { } /// Gets the computed hash value. - pub fn computed_hash(&self) -> Option<&(HashAlgorithm, Vec<u8>)> { - self.computed_hash.as_ref() + pub fn computed_hash(&self) -> Option<&[u8]> { + self.computed_hash.as_ref().map(|d| &d[..]) } /// Sets the computed hash value. - pub fn set_computed_hash(&mut self, hash: Option<(HashAlgorithm, Vec<u8>)>) - -> Option<(HashAlgorithm, Vec<u8>)> + pub fn set_computed_hash(&mut self, hash: Option<Vec<u8>>) + -> Option<Vec<u8>> { ::std::mem::replace(&mut self.computed_hash, hash) } @@ -699,8 +699,8 @@ impl Signature4 { return Err(Error::UnsupportedSignatureType(self.typ()).into()); } - if let Some((hash_algo, ref hash)) = self.computed_hash { - self.verify_hash(key, hash_algo, hash) + if let Some(ref hash) = self.computed_hash { + self.verify_hash(key, self.hash_algo(), hash) } else { Err(Error::BadSignature("Hash not computed.".to_string()).into()) } diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs index ac484e42..db591304 100644 --- a/openpgp/src/parse/parse.rs +++ b/openpgp/src/parse/parse.rs @@ -1058,7 +1058,7 @@ impl Signature4 { { t!("popped a {:?} HashedReader", hash_algo); computed_hash = Some((cookie.signature_level(), - hash_algo, hash.clone())); + hash.clone())); } if cookie.sig_group_unused() { @@ -1072,14 +1072,14 @@ impl Signature4 { } } - if let Some((level, algo, mut hash)) = computed_hash { + if let Some((level, mut hash)) = computed_hash { if let Packet::Signature(ref mut sig) = pp.packet { sig.hash(&mut hash); let mut digest = vec![0u8; hash.digest_size()]; hash.digest(&mut digest); - sig.set_computed_hash(Some((algo, digest))); + sig.set_computed_hash(Some(digest)); sig.set_level(level); } else { unreachable!() @@ -1388,12 +1388,12 @@ fn one_pass_sig_test () { crate::fmt::to_hex(&test.hash_prefix[sigs][..], false), crate::fmt::to_hex(sig.hash_prefix(), false)); eprintln!(" computed hash: {}", - crate::fmt::to_hex(&sig.computed_hash().unwrap().1, + crate::fmt::to_hex(&sig.computed_hash().unwrap(), false)); assert_eq!(&test.hash_prefix[sigs], sig.hash_prefix()); assert_eq!(&test.hash_prefix[sigs][..], - &sig.computed_hash().unwrap().1[..2]); + &sig.computed_hash().unwrap()[..2]); sigs += 1; } else if one_pass_sigs > 0 { diff --git a/sqv/src/sqv.rs b/sqv/src/sqv.rs index 4b640a42..b2eecdda 100644 --- a/sqv/src/sqv.rs +++ b/sqv/src/sqv.rs @@ -260,8 +260,7 @@ fn real_main() -> Result<(), failure::Error> { let mut digest = vec![0u8; hash.digest_size()]; hash.digest(&mut digest); - let hash_algo = sig.hash_algo(); - sig.set_computed_hash(Some((hash_algo, digest))); + sig.set_computed_hash(Some(digest)); match sig.verify(key) { Ok(true) => { |