diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2021-04-07 17:52:18 +0200 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2021-04-09 13:13:59 +0200 |
commit | baecfecbf953aa9e40f16084b927f35b69efc8f0 (patch) | |
tree | bac7c53d32187d6eff22d231dd556b4ada40d50f /openpgp | |
parent | 4d7ecc72b384a9c30e7024eb2ebfaede9882db06 (diff) |
Lint: Use matches! macro.
- https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/armor.rs | 10 | ||||
-rw-r--r-- | openpgp/src/cert/amalgamation/key.rs | 11 | ||||
-rw-r--r-- | openpgp/src/cert/parser/mod.rs | 36 | ||||
-rw-r--r-- | openpgp/src/crypto/s2k.rs | 6 | ||||
-rw-r--r-- | openpgp/src/keyhandle.rs | 8 | ||||
-rw-r--r-- | openpgp/src/message/mod.rs | 34 | ||||
-rw-r--r-- | openpgp/src/packet/key.rs | 5 | ||||
-rw-r--r-- | openpgp/src/packet/signature.rs | 5 | ||||
-rw-r--r-- | openpgp/src/packet/signature/subpacket.rs | 8 | ||||
-rw-r--r-- | openpgp/src/parse.rs | 6 | ||||
-rw-r--r-- | openpgp/src/policy.rs | 7 | ||||
-rw-r--r-- | openpgp/src/regex/mod.rs | 6 | ||||
-rw-r--r-- | openpgp/src/serialize/stream.rs | 8 | ||||
-rw-r--r-- | openpgp/src/types/mod.rs | 23 |
14 files changed, 54 insertions, 119 deletions
diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs index 3ac9886a..1ba52ae9 100644 --- a/openpgp/src/armor.rs +++ b/openpgp/src/armor.rs @@ -884,14 +884,12 @@ impl<'a> Reader<'a> { lines += 1; // Ignore leading whitespace, etc. - while match self.source.data_hard(1)?[0] { + while matches!(self.source.data_hard(1)?[0], // Skip some whitespace (previously .is_ascii_whitespace()) - b' ' | b'\t' | b'\r' | b'\n' => true, + b' ' | b'\t' | b'\r' | b'\n' | // Also skip common quote characters - b'>' | b'|' | b']' | b'}' => true, - // Do not skip anything else - _ => false, - } { + b'>' | b'|' | b']' | b'}' ) + { let c = self.source.data(1)?[0]; if c == b'\n' { // We found a newline while walking whitespace, reset prefix diff --git a/openpgp/src/cert/amalgamation/key.rs b/openpgp/src/cert/amalgamation/key.rs index 40c0fa33..7e6a1d20 100644 --- a/openpgp/src/cert/amalgamation/key.rs +++ b/openpgp/src/cert/amalgamation/key.rs @@ -2346,13 +2346,10 @@ mod test { // Remove the direct key signatures. let cert = Cert::from_packets(Vec::from(cert) .into_iter() - .filter(|p| { - match p { - Packet::Signature(s) - if s.typ() == SignatureType::DirectKey => false, - _ => true, - } - }))?; + .filter(|p| ! matches!( + p, + Packet::Signature(s) if s.typ() == SignatureType::DirectKey + )))?; let vc = cert.with_policy(p, None)?; diff --git a/openpgp/src/cert/parser/mod.rs b/openpgp/src/cert/parser/mod.rs index 6b7369a9..9e888e58 100644 --- a/openpgp/src/cert/parser/mod.rs +++ b/openpgp/src/cert/parser/mod.rs @@ -51,11 +51,7 @@ impl KeyringValidity { /// Note: a `KeyringValidator` will only return this after /// `KeyringValidator::finish` has been called. pub fn is_keyring(&self) -> bool { - if let KeyringValidity::Keyring = self { - true - } else { - false - } + matches!(self, KeyringValidity::Keyring) } /// Returns whether the packet sequence is a valid Keyring prefix. @@ -63,21 +59,13 @@ impl KeyringValidity { /// Note: a `KeyringValidator` will only return this before /// `KeyringValidator::finish` has been called. pub fn is_keyring_prefix(&self) -> bool { - if let KeyringValidity::KeyringPrefix = self { - true - } else { - false - } + matches!(self, KeyringValidity::KeyringPrefix) } /// Returns whether the packet sequence is definitely not a valid /// keyring. pub fn is_err(&self) -> bool { - if let KeyringValidity::Error(_) = self { - true - } else { - false - } + matches!(self, KeyringValidity::Error(_)) } } @@ -257,11 +245,7 @@ impl CertValidity { /// Note: a `CertValidator` will only return this after /// `CertValidator::finish` has been called. pub fn is_cert(&self) -> bool { - if let CertValidity::Cert = self { - true - } else { - false - } + matches!(self, CertValidity::Cert) } /// Returns whether the packet sequence is a valid Cert prefix. @@ -269,21 +253,13 @@ impl CertValidity { /// Note: a `CertValidator` will only return this before /// `CertValidator::finish` has been called. pub fn is_cert_prefix(&self) -> bool { - if let CertValidity::CertPrefix = self { - true - } else { - false - } + matches!(self, CertValidity::CertPrefix) } /// Returns whether the packet sequence is definitely not a valid /// Cert. pub fn is_err(&self) -> bool { - if let CertValidity::Error(_) = self { - true - } else { - false - } + matches!(self, CertValidity::Error(_)) } } diff --git a/openpgp/src/crypto/s2k.rs b/openpgp/src/crypto/s2k.rs index eae95b90..72bd4466 100644 --- a/openpgp/src/crypto/s2k.rs +++ b/openpgp/src/crypto/s2k.rs @@ -245,10 +245,8 @@ impl S2K { /// Returns whether this S2K mechanism is supported. pub fn is_supported(&self) -> bool { use self::S2K::*; - #[allow(deprecated)] - match self { - Simple { .. } | Salted { .. } | Iterated { .. } => true, - _ => false, + #[allow(deprecated)] { + matches!(self, Simple { .. } | Salted { .. } | Iterated { .. }) } } diff --git a/openpgp/src/keyhandle.rs b/openpgp/src/keyhandle.rs index 607cb60f..e1afb93b 100644 --- a/openpgp/src/keyhandle.rs +++ b/openpgp/src/keyhandle.rs @@ -333,11 +333,9 @@ impl KeyHandle { /// # Ok(()) } /// ``` pub fn is_invalid(&self) -> bool { - match self { - KeyHandle::Fingerprint(Fingerprint::Invalid(_)) => true, - KeyHandle::KeyID(KeyID::Invalid(_)) => true, - _ => false, - } + matches!(self, + KeyHandle::Fingerprint(Fingerprint::Invalid(_)) + | KeyHandle::KeyID(KeyID::Invalid(_))) } /// Converts this `KeyHandle` to its canonical hexadecimal diff --git a/openpgp/src/message/mod.rs b/openpgp/src/message/mod.rs index 3a2903d6..b4ace1aa 100644 --- a/openpgp/src/message/mod.rs +++ b/openpgp/src/message/mod.rs @@ -88,11 +88,7 @@ impl MessageValidity { /// Note: a `MessageValidator` will only return this after /// `MessageValidator::finish` has been called. pub fn is_message(&self) -> bool { - if let MessageValidity::Message = self { - true - } else { - false - } + matches!(self, MessageValidity::Message) } /// Returns whether the packet sequence forms a valid message @@ -101,21 +97,13 @@ impl MessageValidity { /// Note: a `MessageValidator` will only return this before /// `MessageValidator::finish` has been called. pub fn is_message_prefix(&self) -> bool { - if let MessageValidity::MessagePrefix = self { - true - } else { - false - } + matches!(self, MessageValidity::MessagePrefix) } /// Returns whether the packet sequence is definitely not a valid /// OpenPGP Message. pub fn is_err(&self) -> bool { - if let MessageValidity::Error(_) = self { - true - } else { - false - } + matches!(self, MessageValidity::Error(_)) } } @@ -1194,7 +1182,7 @@ mod tests { let mut l = MessageValidator::new(); l.push_token(Token::Literal, &[0]); l.finish(); - assert!(if let MessageValidity::Message = l.check() { true } else { false }); + assert!(matches!(l.check(), MessageValidity::Message)); } #[test] @@ -1205,7 +1193,7 @@ mod tests { l.push_token(Token::Literal, &[0]); l.finish(); - assert!(if let MessageValidity::Message = l.check() { true } else { false }); + assert!(matches!(l.check(), MessageValidity::Message)); } #[test] @@ -1217,7 +1205,7 @@ mod tests { l.push(Tag::Literal, &[0]); l.finish(); - assert!(if let MessageValidity::Message = l.check() { true } else { false }); + assert!(matches!(l.check(), MessageValidity::Message)); } #[test] @@ -1227,7 +1215,7 @@ mod tests { let mut l = MessageValidator::new(); l.finish(); - assert!(if let MessageValidity::Error(_) = l.check() { true } else { false }); + assert!(matches!(l.check(), MessageValidity::Error(_))); } #[test] @@ -1237,17 +1225,17 @@ mod tests { // No packets will return an error. let mut l = MessageValidator::new(); - assert!(if let MessageValidity::MessagePrefix = l.check() { true } else { false }); + assert!(matches!(l.check(), MessageValidity::MessagePrefix)); l.finish(); - assert!(if let MessageValidity::Error(_) = l.check() { true } else { false }); + assert!(matches!(l.check(), MessageValidity::Error(_))); // Simple one-literal message. let mut l = MessageValidator::new(); l.push(Tag::Literal, &[0]); - assert!(if let MessageValidity::MessagePrefix = l.check() { true } else { false }); + assert!(matches!(l.check(), MessageValidity::MessagePrefix)); l.finish(); - assert!(if let MessageValidity::Message = l.check() { true } else { false }); + assert!(matches!(l.check(), MessageValidity::Message)); } } diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index 084ec50c..377a8204 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -1100,10 +1100,7 @@ impl<P, R> Key4<P, R> /// This returns false if the `Key` doesn't contain any secret key /// material. pub fn has_unencrypted_secret(&self) -> bool { - match self.secret { - Some(SecretKeyMaterial::Unencrypted { .. }) => true, - _ => false, - } + matches!(self.secret, Some(SecretKeyMaterial::Unencrypted { .. })) } /// Returns `Key`'s secret key material, if any. diff --git a/openpgp/src/packet/signature.rs b/openpgp/src/packet/signature.rs index eaa0c4a4..0b1694e4 100644 --- a/openpgp/src/packet/signature.rs +++ b/openpgp/src/packet/signature.rs @@ -2229,10 +2229,7 @@ impl crate::packet::Signature { // Filters subpackets that usually are in the unhashed area. fn prefer(p: &Subpacket) -> bool { use SubpacketTag::*; - match p.tag() { - Issuer | EmbeddedSignature | IssuerFingerprint => true, - _ => false, - } + matches!(p.tag(), Issuer | EmbeddedSignature | IssuerFingerprint) } // Collect subpackets keeping track of the size. diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index fc619848..abfe694d 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -5458,11 +5458,9 @@ impl signature::SignatureBuilder { F: Into<Option<NotationDataFlags>>, { self.hashed_area.packets.retain(|s| { - match s.value { - SubpacketValue::NotationData(ref v) - if v.name == name.as_ref() => false, - _ => true, - } + ! matches!( + s.value, + SubpacketValue::NotationData(ref v) if v.name == name.as_ref()) }); self.add_notation(name.as_ref(), value.as_ref(), flags.into().unwrap_or_else(NotationDataFlags::empty), diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index f27a2bef..3fc136c2 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -3626,11 +3626,7 @@ assert_send_and_sync!(PacketParserResult<'_>); impl<'a> PacketParserResult<'a> { /// Returns `true` if the result is `EOF`. pub fn is_eof(&self) -> bool { - if let PacketParserResult::EOF(_) = self { - true - } else { - false - } + matches!(self, PacketParserResult::EOF(_)) } /// Returns `true` if the result is `Some`. diff --git a/openpgp/src/policy.rs b/openpgp/src/policy.rs index c915d06d..ee006161 100644 --- a/openpgp/src/policy.rs +++ b/openpgp/src/policy.rs @@ -1292,12 +1292,9 @@ impl<'a> Policy for StandardPolicy<'a> { fn signature(&self, sig: &Signature, sec: HashAlgoSecurity) -> Result<()> { let time = self.time.unwrap_or_else(Timestamp::now); - let rev = match sig.typ() { - SignatureType::KeyRevocation + let rev = matches!(sig.typ(), SignatureType::KeyRevocation | SignatureType::SubkeyRevocation - | SignatureType::CertificationRevocation => true, - _ => false, - }; + | SignatureType::CertificationRevocation); // Note: collision resistance requires 2nd pre-image resistance. if sec == HashAlgoSecurity::CollisionResistance { diff --git a/openpgp/src/regex/mod.rs b/openpgp/src/regex/mod.rs index 1e9e3d7d..6d3cd408 100644 --- a/openpgp/src/regex/mod.rs +++ b/openpgp/src/regex/mod.rs @@ -923,11 +923,7 @@ impl RegexSet { /// # Ok(()) } /// ``` pub fn matches_everything(&self) -> bool { - if let RegexSet_::Everything = self.re_set { - true - } else { - false - } + matches!(self.re_set, RegexSet_::Everything) } /// Controls whether strings with control characters are allowed. diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs index 7c4eee5c..1bc4b507 100644 --- a/openpgp/src/serialize/stream.rs +++ b/openpgp/src/serialize/stream.rs @@ -1669,14 +1669,10 @@ impl<'a> LiteralWriter<'a> { // Signer, and if so, we pop it off the stack and // store it in 'self.signature_writer'. let signer_above = - if let &Cookie { + matches!(self.inner.cookie_ref(), &Cookie { private: Private::Signer{..}, .. - } = self.inner.cookie_ref() { - true - } else { - false - }; + }); if signer_above { let stack = self.inner.pop()?; diff --git a/openpgp/src/types/mod.rs b/openpgp/src/types/mod.rs index 12ba45c2..9c33f47a 100644 --- a/openpgp/src/types/mod.rs +++ b/openpgp/src/types/mod.rs @@ -145,11 +145,13 @@ impl PublicKeyAlgorithm { /// ``` pub fn for_signing(&self) -> bool { use self::PublicKeyAlgorithm::*; - #[allow(deprecated)] - match &self { - RSAEncryptSign | RSASign | DSA | ECDSA | ElGamalEncryptSign - | EdDSA => true, - _ => false, + #[allow(deprecated)] { + matches!(self, RSAEncryptSign + | RSASign + | DSA + | ECDSA + | ElGamalEncryptSign + | EdDSA) } } @@ -167,11 +169,12 @@ impl PublicKeyAlgorithm { /// ``` pub fn for_encryption(&self) -> bool { use self::PublicKeyAlgorithm::*; - #[allow(deprecated)] - match &self { - RSAEncryptSign | RSAEncrypt | ElGamalEncrypt | ECDH - | ElGamalEncryptSign => true, - _ => false, + #[allow(deprecated)] { + matches!(self, RSAEncryptSign + | RSAEncrypt + | ElGamalEncrypt + | ECDH + | ElGamalEncryptSign) } } |