summaryrefslogtreecommitdiffstats
path: root/openpgp/src
diff options
context:
space:
mode:
authorIgor Matuszewski <igor@sequoia-pgp.org>2020-10-26 22:52:26 +0100
committerIgor Matuszewski <igor@sequoia-pgp.org>2020-10-26 22:53:50 +0100
commit85353786abf2fa87746ae5a6a25e60cf88411f66 (patch)
tree3f9ecf6ec49338691f322ea16e9f65e76fa8e3bc /openpgp/src
parent0f1fc8e2e62fb6da00d3249949b233fbe6d69a6b (diff)
openpgp: Refactor some matches for legibility
Diffstat (limited to 'openpgp/src')
-rw-r--r--openpgp/src/cert/parser/mod.rs22
-rw-r--r--openpgp/src/packet/header/mod.rs20
2 files changed, 17 insertions, 25 deletions
diff --git a/openpgp/src/cert/parser/mod.rs b/openpgp/src/cert/parser/mod.rs
index e7c0cdea..5538bbf1 100644
--- a/openpgp/src/cert/parser/mod.rs
+++ b/openpgp/src/cert/parser/mod.rs
@@ -143,22 +143,18 @@ impl KeyringValidator {
return;
}
- match token {
- Token::PublicKey(_) | Token::SecretKey(_) => {
- self.tokens.clear();
- self.n_keys += 1;
- },
- _ => (),
+ if let Token::PublicKey(_) | Token::SecretKey(_) = token {
+ self.tokens.clear();
+ self.n_keys += 1;
}
self.n_packets += 1;
- if matches!(&token, Token::Signature(None))
- && matches!(self.tokens.last(), Some(Token::Signature(None)))
- {
- // Compress multiple signatures in a row. This is
- // essential for dealing with flooded keys.
- } else {
- self.tokens.push(token);
+ match (&token, self.tokens.last()) {
+ (Token::Signature(None), Some(Token::Signature(None))) => {
+ // Compress multiple signatures in a row. This is
+ // essential for dealing with flooded keys
+ },
+ _ => self.tokens.push(token),
}
}
diff --git a/openpgp/src/packet/header/mod.rs b/openpgp/src/packet/header/mod.rs
index 43ca9232..95f2986b 100644
--- a/openpgp/src/packet/header/mod.rs
+++ b/openpgp/src/packet/header/mod.rs
@@ -78,18 +78,14 @@ impl Header {
pub fn valid(&self, future_compatible: bool) -> Result<()> {
let tag = self.ctb.tag();
- // Reserved packets are never valid.
- if tag == Tag::Reserved {
- return Err(Error::UnsupportedPacketType(tag).into());
- }
-
- // Unknown packets are not valid unless we want future
- // compatibility.
- if ! future_compatible
- && (matches!(tag, Tag::Unknown(_))
- || matches!(tag, Tag::Private(_)))
- {
- return Err(Error::UnsupportedPacketType(tag).into());
+ match tag {
+ // Reserved packets are never valid.
+ Tag::Reserved =>
+ return Err(Error::UnsupportedPacketType(tag).into()),
+ // Unknown packets are not valid unless we want future compatibility.
+ Tag::Unknown(_) | Tag::Private(_) if !future_compatible =>
+ return Err(Error::UnsupportedPacketType(tag).into()),
+ _ => (),
}
// An implementation MAY use Partial Body Lengths for data