summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-01-22 11:49:14 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-01-22 11:49:14 +0100
commite424dca53ebbe10cc0f7ffc7bb959442d57730fe (patch)
treef5ec18301c90051ac7c78ebf9c672bf2c10200dd
parent84d2fb9a3b9e5bdfacb429c7ac2f6d9379c4a8ce (diff)
openpgp: Turn macro into a function.
-rw-r--r--openpgp/src/cert/components.rs104
1 files changed, 51 insertions, 53 deletions
diff --git a/openpgp/src/cert/components.rs b/openpgp/src/cert/components.rs
index f69ebce5..7b602cfd 100644
--- a/openpgp/src/cert/components.rs
+++ b/openpgp/src/cert/components.rs
@@ -238,64 +238,62 @@ impl<C> ComponentBinding<C> {
selfsig.signature_alive(t, time::Duration::new(0, 0)).is_ok());
}
- macro_rules! check {
- ($revs:expr) => ({
- let revs = $revs.iter().filter_map(|rev| {
- if hard_revocations_are_final
- && rev.reason_for_revocation()
- .map(|(r, _)| {
- r.revocation_type() == RevocationType::Hard
- })
- // If there is no Reason for Revocation
- // packet, assume that it is a hard
- // revocation.
- .unwrap_or(true)
- {
- t!(" got a hard revocation: {:?}, {:?}",
- rev.signature_creation_time()
- .unwrap_or_else(time_zero),
- rev.reason_for_revocation()
- .map(|r| (r.0, String::from_utf8_lossy(r.1))));
- Some(rev)
- } else if selfsig_creation_time
- > rev.signature_creation_time()
- .unwrap_or_else(time_zero)
- {
- t!(" ignoring out of date revocation ({:?})",
- rev.signature_creation_time()
- .unwrap_or_else(time_zero));
- None
- } else if
- ! rev.signature_alive(t, time::Duration::new(0, 0))
- .is_ok()
- {
- t!(" ignoring revocation that is not alive ({:?} - {:?})",
- rev.signature_creation_time()
- .unwrap_or_else(time_zero),
- rev.signature_expiration_time()
- .unwrap_or_else(|| time::Duration::new(0, 0)));
- None
- } else {
- t!(" got a revocation: {:?} ({:?})",
- rev.signature_creation_time()
- .unwrap_or_else(time_zero),
- rev.reason_for_revocation()
- .map(|r| (r.0, String::from_utf8_lossy(r.1))));
- Some(rev)
- }
- }).collect::<Vec<&Signature>>();
-
- if revs.len() == 0 {
+ let check = |revs: &'a [Signature]| -> Option<Vec<&'a Signature>> {
+ let revs = revs.iter().filter_map(|rev| {
+ if hard_revocations_are_final
+ && rev.reason_for_revocation()
+ .map(|(r, _)| {
+ r.revocation_type() == RevocationType::Hard
+ })
+ // If there is no Reason for Revocation
+ // packet, assume that it is a hard
+ // revocation.
+ .unwrap_or(true)
+ {
+ t!(" got a hard revocation: {:?}, {:?}",
+ rev.signature_creation_time()
+ .unwrap_or_else(time_zero),
+ rev.reason_for_revocation()
+ .map(|r| (r.0, String::from_utf8_lossy(r.1))));
+ Some(rev)
+ } else if selfsig_creation_time
+ > rev.signature_creation_time()
+ .unwrap_or_else(time_zero)
+ {
+ t!(" ignoring out of date revocation ({:?})",
+ rev.signature_creation_time()
+ .unwrap_or_else(time_zero));
+ None
+ } else if
+ ! rev.signature_alive(t, time::Duration::new(0, 0))
+ .is_ok()
+ {
+ t!(" ignoring revocation that is not alive ({:?} - {:?})",
+ rev.signature_creation_time()
+ .unwrap_or_else(time_zero),
+ rev.signature_expiration_time()
+ .unwrap_or_else(|| time::Duration::new(0, 0)));
None
} else {
- Some(revs)
+ t!(" got a revocation: {:?} ({:?})",
+ rev.signature_creation_time()
+ .unwrap_or_else(time_zero),
+ rev.reason_for_revocation()
+ .map(|r| (r.0, String::from_utf8_lossy(r.1))));
+ Some(rev)
}
- })
- }
+ }).collect::<Vec<&Signature>>();
+
+ if revs.len() == 0 {
+ None
+ } else {
+ Some(revs)
+ }
+ };
- if let Some(revs) = check!(&self.self_revocations) {
+ if let Some(revs) = check(&self.self_revocations) {
RevocationStatus::Revoked(revs)
- } else if let Some(revs) = check!(&self.other_revocations) {
+ } else if let Some(revs) = check(&self.other_revocations) {
RevocationStatus::CouldBe(revs)
} else {
RevocationStatus::NotAsFarAsWeKnow