diff options
-rw-r--r-- | ipc/src/core.rs | 10 | ||||
-rw-r--r-- | openpgp/src/cert/amalgamation/key/iter.rs | 48 | ||||
-rw-r--r-- | openpgp/src/cert/builder.rs | 36 | ||||
-rw-r--r-- | openpgp/src/cert/parser/mod.rs | 8 | ||||
-rw-r--r-- | openpgp/src/packet/signature.rs | 12 | ||||
-rw-r--r-- | openpgp/src/parse.rs | 10 | ||||
-rw-r--r-- | openpgp/src/parse/stream.rs | 8 | ||||
-rw-r--r-- | openpgp/src/regex/mod.rs | 12 | ||||
-rw-r--r-- | openpgp/src/serialize/stream.rs | 8 | ||||
-rw-r--r-- | sq/src/commands/dump.rs | 12 | ||||
-rw-r--r-- | sq/src/sq.rs | 6 |
11 files changed, 66 insertions, 104 deletions
diff --git a/ipc/src/core.rs b/ipc/src/core.rs index b4dd928a..6712921b 100644 --- a/ipc/src/core.rs +++ b/ipc/src/core.rs @@ -179,12 +179,10 @@ impl Config { let tmp = tempfile::Builder::new().prefix("sequoia").tempdir()?; c.home = tmp.into_path(); c.cleanup = true; - } else { - if home_not_set { - c.home = dirs::home_dir() - .ok_or_else(|| anyhow::anyhow!("Failed to get users home directory"))? - .join(".sequoia"); - } + } else if home_not_set { + c.home = dirs::home_dir() + .ok_or_else(|| anyhow::anyhow!("Failed to get users home directory"))? + .join(".sequoia"); } Ok(c) } diff --git a/openpgp/src/cert/amalgamation/key/iter.rs b/openpgp/src/cert/amalgamation/key/iter.rs index 370a4e43..d2ec0fe6 100644 --- a/openpgp/src/cert/amalgamation/key/iter.rs +++ b/openpgp/src/cert/amalgamation/key/iter.rs @@ -175,11 +175,9 @@ impl<'a, P, R> KeyAmalgamationIter<'a, P, R> t!("PK algo is supported... skipping."); continue; } - } else { - if want_supported { - t!("PK algo is not supported... skipping."); - continue; - } + } else if want_supported { + t!("PK algo is not supported... skipping."); + continue; } } @@ -190,11 +188,9 @@ impl<'a, P, R> KeyAmalgamationIter<'a, P, R> t!("Have a secret... skipping."); continue; } - } else { - if want_secret { - t!("No secret... skipping."); - continue; - } + } else if want_secret { + t!("No secret... skipping."); + continue; } } @@ -205,11 +201,9 @@ impl<'a, P, R> KeyAmalgamationIter<'a, P, R> t!("Unencrypted secret... skipping."); continue; } - } else { - if want_unencrypted_secret { - t!("Encrypted secret... skipping."); - continue; - } + } else if want_unencrypted_secret { + t!("Encrypted secret... skipping."); + continue; } } else { // No secret. @@ -797,11 +791,9 @@ impl<'a, P, R> ValidKeyAmalgamationIter<'a, P, R> t!("PK algo is supported... skipping."); continue; } - } else { - if want_supported { - t!("PK algo is not supported... skipping."); - continue; - } + } else if want_supported { + t!("PK algo is not supported... skipping."); + continue; } } @@ -843,11 +835,9 @@ impl<'a, P, R> ValidKeyAmalgamationIter<'a, P, R> t!("Have a secret... skipping."); continue; } - } else { - if want_secret { - t!("No secret... skipping."); - continue; - } + } else if want_secret { + t!("No secret... skipping."); + continue; } } @@ -858,11 +848,9 @@ impl<'a, P, R> ValidKeyAmalgamationIter<'a, P, R> t!("Unencrypted secret... skipping."); continue; } - } else { - if want_unencrypted_secret { - t!("Encrypted secret... skipping."); - continue; - } + } else if want_unencrypted_secret { + t!("Encrypted secret... skipping."); + continue; } } else { // No secret. diff --git a/openpgp/src/cert/builder.rs b/openpgp/src/cert/builder.rs index 0ceb0579..235f2cd9 100644 --- a/openpgp/src/cert/builder.rs +++ b/openpgp/src/cert/builder.rs @@ -1336,17 +1336,15 @@ impl CertBuilder<'_> { a.remove_all(SubpacketTag::PrimaryUserID); Ok(a) })?; + } else if have_primary_user_thing { + // Check if this is the first explicitly selected + // user thing. + emitted_primary_user_thing |= + sig.primary_userid().unwrap_or(false); } else { - if have_primary_user_thing { - // Check if this is the first explicitly selected - // user thing. - emitted_primary_user_thing |= - sig.primary_userid().unwrap_or(false); - } else { - // Implicitly mark the first as primary. - sig = sig.set_primary_userid(true)?; - emitted_primary_user_thing = true; - } + // Implicitly mark the first as primary. + sig = sig.set_primary_userid(true)?; + emitted_primary_user_thing = true; } let signature = uid.bind(&mut signer, &cert, sig)?; @@ -1368,17 +1366,15 @@ impl CertBuilder<'_> { a.remove_all(SubpacketTag::PrimaryUserID); Ok(a) })?; + } else if have_primary_user_thing { + // Check if this is the first explicitly selected + // user thing. + emitted_primary_user_thing |= + sig.primary_userid().unwrap_or(false); } else { - if have_primary_user_thing { - // Check if this is the first explicitly selected - // user thing. - emitted_primary_user_thing |= - sig.primary_userid().unwrap_or(false); - } else { - // Implicitly mark the first as primary. - sig = sig.set_primary_userid(true)?; - emitted_primary_user_thing = true; - } + // Implicitly mark the first as primary. + sig = sig.set_primary_userid(true)?; + emitted_primary_user_thing = true; } let signature = ua.bind(&mut signer, &cert, sig)?; diff --git a/openpgp/src/cert/parser/mod.rs b/openpgp/src/cert/parser/mod.rs index 02516428..15afbdd9 100644 --- a/openpgp/src/cert/parser/mod.rs +++ b/openpgp/src/cert/parser/mod.rs @@ -904,12 +904,10 @@ pub(crate) fn split_sigs<C>(primary: &KeyHandle, primary_keyid: &KeyHandle, } else { other_revs.push(sig); } + } else if is_selfsig { + self_signatures.push(sig); } else { - if is_selfsig { - self_signatures.push(sig); - } else { - certifications.push(sig); - } + certifications.push(sig); } } diff --git a/openpgp/src/packet/signature.rs b/openpgp/src/packet/signature.rs index 2db99a39..359ea7a5 100644 --- a/openpgp/src/packet/signature.rs +++ b/openpgp/src/packet/signature.rs @@ -2316,10 +2316,8 @@ impl crate::packet::Signature { }; let l = p.serialized_len(); - if size + l <= std::u16::MAX as usize { - if acc.insert(p.clone()) { - size += l; - } + if size + l <= std::u16::MAX as usize && acc.insert(p.clone()) { + size += l; } } @@ -2343,10 +2341,8 @@ impl crate::packet::Signature { .filter(|p| eligible(p) && ! p.authenticated() && ! prefer(p))) { let l = p.serialized_len(); - if size + l <= std::u16::MAX as usize { - if acc.insert(p.clone()) { - size += l; - } + if size + l <= std::u16::MAX as usize && acc.insert(p.clone()) { + size += l; } } assert!(size <= std::u16::MAX as usize); diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index 8a323b89..5cf7c5f5 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -2229,12 +2229,10 @@ impl Key4<key::UnspecifiedParts, key::UnspecifiedRole> format!("Unexpected secret key found in {:?} packet", tag) ).into()); } - } else { - if tag == Tag::SecretKey || tag == Tag::SecretSubkey { - return php.error(Error::MalformedPacket( - format!("Expected secret key in {:?} packet", tag) - ).into()); - } + } else if tag == Tag::SecretKey || tag == Tag::SecretSubkey { + return php.error(Error::MalformedPacket( + format!("Expected secret key in {:?} packet", tag) + ).into()); } fn k<R>(creation_time: u32, diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index efb5755e..8d92dab5 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -2325,11 +2325,9 @@ impl<'a, H: VerificationHelper + DecryptionHelper> Decryptor<'a, H> { format!("Expected signature, got {}", pp.packet.tag())) .into()); } - } else { - if let Err(err) = pp.possible_message() { - t!("Malformed message: {}", err); - return Err(err.context("Malformed OpenPGP message")); - } + } else if let Err(err) = pp.possible_message() { + t!("Malformed message: {}", err); + return Err(err.context("Malformed OpenPGP message")); } let sym_algo_hint = if let Packet::AED(ref aed) = pp.packet { diff --git a/openpgp/src/regex/mod.rs b/openpgp/src/regex/mod.rs index a7e911de..0584bcbe 100644 --- a/openpgp/src/regex/mod.rs +++ b/openpgp/src/regex/mod.rs @@ -453,10 +453,8 @@ impl Regex { /// /// [`char::is_control`]: https://doc.rust-lang.org/std/primitive.char.html#method.is_control pub fn is_match(&self, s: &str) -> bool { - if ! self.disable_sanitizations { - if s.chars().any(char::is_control) { - return false; - } + if ! self.disable_sanitizations && s.chars().any(char::is_control) { + return false; } self.is_match_clean(s) @@ -975,10 +973,8 @@ impl RegexSet { /// # Ok(()) } /// ``` pub fn is_match(&self, s: &str) -> bool { - if ! self.disable_sanitizations { - if s.chars().any(char::is_control) { - return false; - } + if ! self.disable_sanitizations && s.chars().any(char::is_control) { + return false; } match self.re_set { diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs index 53068489..cbfa1117 100644 --- a/openpgp/src/serialize/stream.rs +++ b/openpgp/src/serialize/stream.rs @@ -1409,12 +1409,10 @@ impl<'a> Write for Signer<'a> { // later, we will hash it then. Otherwise, it is // implicitly omitted when the signer is finalized. self.hash_stash.extend_from_slice(&data[l..]); + } else if self.template.typ() == SignatureType::Text { + crate::parse::hash_update_text(&mut self.hash, data); } else { - if self.template.typ() == SignatureType::Text { - crate::parse::hash_update_text(&mut self.hash, data); - } else { - self.hash.update(data); - } + self.hash.update(data); } self.position += amount as u64; } diff --git a/sq/src/commands/dump.rs b/sq/src/commands/dump.rs index 3c1eda31..c2d0aa03 100644 --- a/sq/src/commands/dump.rs +++ b/sq/src/commands/dump.rs @@ -225,14 +225,12 @@ impl PacketDumper { if self.root.is_none() { assert_eq!(depth, 0); self.root = Some(node); + } else if depth == 0 { + let root = self.root.take().unwrap(); + self.dump_tree(output, "", &root)?; + self.root = Some(node); } else { - if depth == 0 { - let root = self.root.take().unwrap(); - self.dump_tree(output, "", &root)?; - self.root = Some(node); - } else { - self.root.as_mut().unwrap().append(depth - 1, node); - } + self.root.as_mut().unwrap().append(depth - 1, node); } Ok(()) } diff --git a/sq/src/sq.rs b/sq/src/sq.rs index 37146bcc..e2ed3130 100644 --- a/sq/src/sq.rs +++ b/sq/src/sq.rs @@ -715,10 +715,8 @@ fn parse_iso8601(s: &str, pad_date_with: chrono::NaiveTime) if let Ok(d) = DateTime::parse_from_str(s, *f) { return Ok(d.into()); } - } else { - if let Ok(d) = chrono::NaiveDateTime::parse_from_str(s, *f) { - return Ok(DateTime::from_utc(d, Utc)); - } + } else if let Ok(d) = chrono::NaiveDateTime::parse_from_str(s, *f) { + return Ok(DateTime::from_utc(d, Utc)); } } for f in &[ |