summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-01-16 16:16:28 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-01-16 16:16:28 +0100
commit70cf33c2e495a51f208322923a9461524224c4d0 (patch)
tree051eb877479f64d9285d97a2f0345a3101028cd9
parente3ca51fc146b7c335762c7e977ab736da9e79999 (diff)
openpgp: Move the high-level methods to packet::Signature.
- Signature4 is only a storage format. The high-level functionality should be implemented on the version enum.
-rw-r--r--openpgp/src/cert/parser/mod.rs54
-rw-r--r--openpgp/src/crypto/asymmetric.rs4
-rw-r--r--openpgp/src/packet/key/mod.rs1
-rw-r--r--openpgp/src/packet/signature/mod.rs6
4 files changed, 29 insertions, 36 deletions
diff --git a/openpgp/src/cert/parser/mod.rs b/openpgp/src/cert/parser/mod.rs
index 53a49beb..739125a4 100644
--- a/openpgp/src/cert/parser/mod.rs
+++ b/openpgp/src/cert/parser/mod.rs
@@ -9,7 +9,6 @@ use crate::{
Error,
KeyHandle,
packet::Tag,
- packet::Signature,
Packet,
parse::{
Parse,
@@ -632,35 +631,30 @@ impl<'a, I: Iterator<Item=Packet>> CertParser<'a, I> {
let mut other_revs = vec![];
for sig in mem::replace(&mut b.certifications, vec![]) {
- match sig {
- Signature::V4(sig) => {
- let typ = sig.typ();
-
- let issuers =
- sig.get_issuers();
- let is_selfsig =
- issuers.contains(primary)
- || issuers.contains(primary_keyid);
-
- use crate::SignatureType::*;
- if typ == KeyRevocation
- || typ == SubkeyRevocation
- || typ == CertificationRevocation
- {
- if is_selfsig {
- self_revs.push(sig.into());
- } else {
- other_revs.push(sig.into());
- }
- } else {
- if is_selfsig {
- self_signatures.push(sig.into());
- } else {
- certifications.push(sig.into());
- }
- }
- },
- Signature::__Nonexhaustive => unreachable!(),
+ let typ = sig.typ();
+
+ let issuers =
+ sig.get_issuers();
+ let is_selfsig =
+ issuers.contains(primary)
+ || issuers.contains(primary_keyid);
+
+ use crate::SignatureType::*;
+ if typ == KeyRevocation
+ || typ == SubkeyRevocation
+ || typ == CertificationRevocation
+ {
+ if is_selfsig {
+ self_revs.push(sig.into());
+ } else {
+ other_revs.push(sig.into());
+ }
+ } else {
+ if is_selfsig {
+ self_signatures.push(sig.into());
+ } else {
+ certifications.push(sig.into());
+ }
}
}
diff --git a/openpgp/src/crypto/asymmetric.rs b/openpgp/src/crypto/asymmetric.rs
index a92b18ec..76729ddb 100644
--- a/openpgp/src/crypto/asymmetric.rs
+++ b/openpgp/src/crypto/asymmetric.rs
@@ -306,9 +306,7 @@ impl<P: key::KeyParts, R: key::KeyRole> Key<P, R> {
}
/// Verifies the given signature.
- pub fn verify(&self,
- sig: &packet::signature::Signature4, // XXX: Should be Signature
- digest: &[u8]) -> Result<bool>
+ pub fn verify(&self, sig: &packet::Signature, digest: &[u8]) -> Result<bool>
{
use crate::PublicKeyAlgorithm::*;
use crate::crypto::mpis::{PublicKey, Signature};
diff --git a/openpgp/src/packet/key/mod.rs b/openpgp/src/packet/key/mod.rs
index 4cfd336e..c334ab4a 100644
--- a/openpgp/src/packet/key/mod.rs
+++ b/openpgp/src/packet/key/mod.rs
@@ -1622,6 +1622,7 @@ mod tests {
mpis::Signature::EdDSA{
r: mpis::MPI::new(r), s: mpis::MPI::new(s)
});
+ let sig: Signature = sig.into();
assert_eq!(sig.verify_message(&key, b"Hello, World\n").unwrap(), true);
}
diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs
index 2dfb5833..3424c85b 100644
--- a/openpgp/src/packet/signature/mod.rs
+++ b/openpgp/src/packet/signature/mod.rs
@@ -515,7 +515,9 @@ impl Signature4 {
pub(crate) fn set_level(&mut self, level: usize) -> usize {
::std::mem::replace(&mut self.level, level)
}
+}
+impl crate::packet::Signature {
/// Collects all the issuers.
///
/// A signature can contain multiple hints as to who issued the
@@ -822,9 +824,7 @@ impl Signature4 {
return Ok(true)
}
- if let Some(super::Signature::V4(backsig)) =
- self.embedded_signature()
- {
+ if let Some(backsig) = self.embedded_signature() {
backsig.verify_primary_key_binding(pk, subkey)
} else {
Err(Error::BadSignature(