summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-09-27 15:32:18 +0300
committerLars Wirzenius <liw@sequoia-pgp.org>2021-09-30 08:31:10 +0300
commitf098a0a37df4cddd98899e4e94def4380a0f1d15 (patch)
treeed8730c1a47147628d3f59d616e340886225b2bd
parent840b597423a2c41e266c2b05275d43c35ab3d652 (diff)
Replace .filter_map with just .filter when possible
If the function or closure passed into .filter_map doesn't do any filtering or mapping. the method call can be replaced with a simple .map or .filter. The clippy lint suggests which. In this change, we can always replace .filter_map with .filter. We also need to change the closure to return a boolean value, since that's what .filter expects. Found by clippy lint unnecessary_filter_map: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map
-rw-r--r--openpgp/src/cert/bundle.rs12
-rw-r--r--openpgp/src/serialize/cert_armored.rs8
2 files changed, 8 insertions, 12 deletions
diff --git a/openpgp/src/cert/bundle.rs b/openpgp/src/cert/bundle.rs
index 8fa65131..ab634aa3 100644
--- a/openpgp/src/cert/bundle.rs
+++ b/openpgp/src/cert/bundle.rs
@@ -613,10 +613,10 @@ impl<C> ComponentBundle<C> {
let check = |revs: &'a [Signature], sec: HashAlgoSecurity|
-> Option<Vec<&'a Signature>>
{
- let revs = revs.iter().filter_map(|rev| {
+ let revs = revs.iter().filter(|rev| {
if let Err(err) = policy.signature(rev, sec) {
t!(" revocation rejected by caller policy: {}", err);
- None
+ false
} else if hard_revocations_are_final
&& rev.reason_for_revocation()
.map(|(r, _)| {
@@ -632,7 +632,7 @@ impl<C> ComponentBundle<C> {
.unwrap_or_else(time_zero),
rev.reason_for_revocation()
.map(|r| (r.0, String::from_utf8_lossy(r.1))));
- Some(rev)
+ true
} else if selfsig_creation_time
> rev.signature_creation_time().unwrap_or_else(time_zero)
{
@@ -641,7 +641,7 @@ impl<C> ComponentBundle<C> {
t!(" newer binding signature trumps soft revocation ({:?} > {:?})",
selfsig_creation_time,
rev.signature_creation_time().unwrap_or_else(time_zero));
- None
+ false
} else if let Err(err)
= rev.signature_alive(t, time::Duration::new(0, 0))
{
@@ -652,13 +652,13 @@ impl<C> ComponentBundle<C> {
rev.signature_validity_period()
.unwrap_or_else(|| time::Duration::new(0, 0)),
err);
- None
+ false
} 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)
+ true
}
}).collect::<Vec<&Signature>>();
diff --git a/openpgp/src/serialize/cert_armored.rs b/openpgp/src/serialize/cert_armored.rs
index ab22ec51..83b68479 100644
--- a/openpgp/src/serialize/cert_armored.rs
+++ b/openpgp/src/serialize/cert_armored.rs
@@ -37,12 +37,8 @@ impl Cert {
// Create a header per userid.
let mut headers: Vec<String> = self.userids().with_policy(p, None)
// Ignore revoked userids.
- .filter_map(|uidb| {
- if let RevocationStatus::Revoked(_) = uidb.revocation_status() {
- None
- } else {
- Some(uidb)
- }
+ .filter(|uidb| {
+ !matches!(uidb.revocation_status(), RevocationStatus::Revoked(_))
// Ignore userids with non-printable characters.
}).filter_map(|uidb| {
let value = str::from_utf8(uidb.userid().value()).ok()?;