diff --git a/src/commands/certify.rs b/src/commands/certify.rs index 25ec0838..ff897e82 100644 --- a/src/commands/certify.rs +++ b/src/commands/certify.rs @@ -147,7 +147,7 @@ pub fn certify(config: Config, c: certify::Command) (Some(_), Some(_)) => unreachable!("conflicting args"), } - let notations = parse_notations(c.notation.unwrap_or_default())?; + let notations = parse_notations(c.notation)?; for (critical, n) in notations { builder = builder.add_notation( n.name(), diff --git a/src/commands/decrypt.rs b/src/commands/decrypt.rs index bb0a97be..0b23ab0b 100644 --- a/src/commands/decrypt.rs +++ b/src/commands/decrypt.rs @@ -188,7 +188,7 @@ impl<'a, 'certdb> VerificationHelper for Helper<'a, 'certdb> { dumper.packet(&mut io::stderr(), pp.recursion_depth() as usize, pp.header().clone(), pp.packet.clone(), - pp.map().cloned(), None)?; + pp.map().cloned(), Vec::new())?; } Ok(()) } diff --git a/src/commands/dump.rs b/src/commands/dump.rs index 0b3d4157..a0ea7cd3 100644 --- a/src/commands/dump.rs +++ b/src/commands/dump.rs @@ -75,15 +75,15 @@ pub fn dump(input: &mut (dyn io::Read + Sync + Send), Packet::Literal(_) => { let mut prefix = vec![0; 40]; let n = pp.read(&mut prefix)?; - Some(vec![ + vec![ format!("Content: {:?}{}", String::from_utf8_lossy(&prefix[..n]), if n == prefix.len() { "..." } else { "" }), - ]) + ] }, Packet::SEIP(_) if sk.is_none() => { message_encrypted = true; - Some(vec!["No session key supplied".into()]) + vec!["No session key supplied".into()] } Packet::SEIP(_) if sk.is_some() => { message_encrypted = true; @@ -113,11 +113,11 @@ pub fn dump(input: &mut (dyn io::Read + Sync + Send), }; fields.push("Decryption failed".into()); } - Some(fields) + fields }, Packet::AED(_) if sk.is_none() => { message_encrypted = true; - Some(vec!["No session key supplied".into()]) + vec!["No session key supplied".into()] } Packet::AED(_) if sk.is_some() => { message_encrypted = true; @@ -137,9 +137,9 @@ pub fn dump(input: &mut (dyn io::Read + Sync + Send), } else { fields.push("Decryption failed".into()); } - Some(fields) + fields }, - _ => None, + _ => Vec::new(), }; let header = pp.header().clone(); @@ -184,13 +184,13 @@ struct Node { header: Header, packet: Packet, map: Option, - additional_fields: Option>, + additional_fields: Vec, children: Vec, } impl Node { fn new(header: Header, packet: Packet, map: Option, - additional_fields: Option>) -> Self { + additional_fields: Vec) -> Self { Node { header, packet, @@ -226,7 +226,7 @@ impl PacketDumper { pub fn packet(&mut self, output: &mut dyn io::Write, depth: usize, header: Header, p: Packet, map: Option, - additional_fields: Option>) + additional_fields: Vec) -> Result<()> { let node = Node::new(header, p, map, additional_fields); if self.root.is_none() { @@ -255,7 +255,7 @@ impl PacketDumper { format!("{}{} ", indent, if node.children.is_empty() { " " } else { "│" }); self.dump_packet(output, &indent_node, Some(&node.header), &node.packet, - node.map.as_ref(), node.additional_fields.as_ref())?; + node.map.as_ref(), &node.additional_fields)?; if node.children.is_empty() { return Ok(()); } @@ -275,7 +275,7 @@ impl PacketDumper { fn dump_packet(&self, mut output: &mut dyn io::Write, i: &str, header: Option<&Header>, p: &Packet, map: Option<&Map>, - additional_fields: Option<&Vec>) + additional_fields: &Vec) -> Result<()> { use self::openpgp::Packet::*; @@ -723,10 +723,8 @@ impl PacketDumper { u => writeln!(output, "{} Unknown variant: {:?}", i, u)?, } - if let Some(fields) = additional_fields { - for field in fields { - writeln!(output, "{} {}", i, field)?; - } + for field in additional_fields { + writeln!(output, "{} {}", i, field)?; } writeln!(output, "{}", i)?; @@ -899,7 +897,7 @@ impl PacketDumper { let indent = format!("{} ", i); write!(output, "{}", indent)?; self.dump_packet(output, &indent, None, &sig.clone().into(), - None, None)?; + None, &Vec::new())?; }, _ => { if s.critical() { diff --git a/src/commands/key.rs b/src/commands/key.rs index 6d0b01e5..db885947 100644 --- a/src/commands/key.rs +++ b/src/commands/key.rs @@ -47,12 +47,11 @@ fn generate( let mut builder = CertBuilder::new(); // User ID - match command.userid { - Some(uids) => for uid in uids { + if command.userid.is_empty() { + eprintln!("No user ID given, using direct key signature"); + } else { + for uid in command.userid { builder = builder.add_userid(uid); - }, - None => { - eprintln!("No user ID given, using direct key signature"); } } diff --git a/src/commands/keyring.rs b/src/commands/keyring.rs index 88875550..6e43b975 100644 --- a/src/commands/keyring.rs +++ b/src/commands/keyring.rs @@ -40,44 +40,36 @@ pub fn dispatch(config: Config, c: keyring::Command) -> Result<()> { match c.subcommand { Filter(command) => { let any_uid_predicates = - command.userid.is_some() - || command.name.is_some() - || command.email.is_some() - || command.domain.is_some(); + ! command.userid.is_empty() + || !command.name.is_empty() + || !command.email.is_empty() + || !command.domain.is_empty(); let uid_predicate = |uid: &UserID| { let mut keep = false; - if let Some(userids) = &command.userid { - for userid in userids { - keep |= uid.value() == userid.as_bytes(); - } + for userid in &command.userid { + keep |= uid.value() == userid.as_bytes(); } - if let Some(names) = &command.name { - for name in names { - keep |= uid - .name().unwrap_or(None) - .map(|n| &n == name) - .unwrap_or(false); - } + for name in &command.name { + keep |= uid + .name().unwrap_or(None) + .map(|n| &n == name) + .unwrap_or(false); } - if let Some(emails) = &command.email { - for email in emails { - keep |= uid - .email().unwrap_or(None) - .map(|n| &n == email) - .unwrap_or(false); - } + for email in &command.email { + keep |= uid + .email().unwrap_or(None) + .map(|n| &n == email) + .unwrap_or(false); } - if let Some(domains) = &command.domain { - for domain in domains { - keep |= uid - .email().unwrap_or(None) - .map(|n| n.ends_with(&format!("@{}", domain))) - .unwrap_or(false); - } + for domain in &command.domain { + keep |= uid + .email().unwrap_or(None) + .map(|n| n.ends_with(&format!("@{}", domain))) + .unwrap_or(false); } keep @@ -86,15 +78,12 @@ pub fn dispatch(config: Config, c: keyring::Command) -> Result<()> { let any_ua_predicates = false; let ua_predicate = |_ua: &UserAttribute| false; - let any_key_predicates = command.handle.is_some(); - let handles: Vec = - if let Some(handles) = &command.handle { - use std::str::FromStr; - handles.iter().map(|h| KeyHandle::from_str(h)) - .collect::>()? - } else { - Vec::with_capacity(0) - }; + let any_key_predicates = ! command.handle.is_empty(); + let handles: Vec = { + use std::str::FromStr; + command.handle.iter().map(|h| KeyHandle::from_str(h)) + .collect::>()? + }; let key_predicate = |key: &Key<_, _>| { let mut keep = false; diff --git a/src/commands/revoke.rs b/src/commands/revoke.rs index 5496812f..f5a50100 100644 --- a/src/commands/revoke.rs +++ b/src/commands/revoke.rs @@ -64,7 +64,7 @@ pub fn revoke_certificate(config: Config, c: revoke::CertificateCommand) -> Resu let time = c.time.map(|t| t.time.into()); - let notations = parse_notations(c.notation.unwrap_or_default())?; + let notations = parse_notations(c.notation)?; revoke( config, @@ -99,7 +99,7 @@ pub fn revoke_subkey(config: Config, c: revoke::SubkeyCommand) -> Result<()> { let time = c.time.map(|t| t.time.into()); - let notations = parse_notations(c.notation.unwrap_or_default())?; + let notations = parse_notations(c.notation)?; revoke( config, @@ -126,7 +126,7 @@ pub fn revoke_userid(config: Config, c: revoke::UseridCommand) -> Result<()> { let time = c.time.map(|t| t.time.into()); - let notations = parse_notations(c.notation.unwrap_or_default())?; + let notations = parse_notations(c.notation)?; revoke( config, diff --git a/src/sq.rs b/src/sq.rs index f31c4328..24536ea3 100644 --- a/src/sq.rs +++ b/src/sq.rs @@ -791,7 +791,7 @@ fn main() -> Result<()> { load_certs(command.secret_key_file.iter().map(|s| s.as_ref()))?; let time = command.time.map(|t| t.time.into()); - let notations = parse_notations(command.notation.unwrap_or_default())?; + let notations = parse_notations(command.notation)?; if let Some(merge) = command.merge { let output = config.create_or_stdout_pgp(output, binary, diff --git a/src/sq_cli/certify.rs b/src/sq_cli/certify.rs index d00a752e..f1f59a47 100644 --- a/src/sq_cli/certify.rs +++ b/src/sq_cli/certify.rs @@ -134,7 +134,7 @@ $ sq certify --time 20130721T0550+0200 neal.pgp ada.pgp ada then it will ignore the signature. The notation is marked as \ being human readable." )] - pub notation: Option>, + pub notation: Vec, #[clap( long = "expires", value_name = "TIME", diff --git a/src/sq_cli/key.rs b/src/sq_cli/key.rs index 526df6dd..48715abb 100644 --- a/src/sq_cli/key.rs +++ b/src/sq_cli/key.rs @@ -83,7 +83,7 @@ pub struct GenerateCommand { value_name = "EMAIL", help = "Adds a userid to the key" )] - pub userid: Option>, + pub userid: Vec, #[clap( short = 'c', long = "cipher-suite", diff --git a/src/sq_cli/keyring.rs b/src/sq_cli/keyring.rs index 510b23b5..c8431dee 100644 --- a/src/sq_cli/keyring.rs +++ b/src/sq_cli/keyring.rs @@ -92,7 +92,7 @@ pub struct FilterCommand { long_help = "Case-sensitively matches on the \ user id, requiring an exact match.", )] - pub userid: Option>, + pub userid: Vec, #[clap( long = "name", value_name = "NAME", @@ -102,7 +102,7 @@ pub struct FilterCommand { and case-sensitively matches on the \ name, requiring an exact match.", )] - pub name: Option>, + pub name: Vec, #[clap( long = "email", value_name = "ADDRESS", @@ -112,7 +112,7 @@ pub struct FilterCommand { address and case-sensitively matches \ on the email address, requiring an exact match.", )] - pub email: Option>, + pub email: Vec, #[clap( long = "domain", value_name = "FQDN", @@ -123,7 +123,7 @@ pub struct FilterCommand { on the domain of the email address, \ requiring an exact match.", )] - pub domain: Option>, + pub domain: Vec, #[clap( long = "handle", value_name = "FINGERPRINT|KEYID", @@ -133,7 +133,7 @@ pub struct FilterCommand { including those certificates that match the \ given fingerprint or key id.", )] - pub handle: Option>, + pub handle: Vec, #[clap( short = 'P', long = "prune-certs", diff --git a/src/sq_cli/revoke.rs b/src/sq_cli/revoke.rs index 13d2ddfc..19bca39c 100644 --- a/src/sq_cli/revoke.rs +++ b/src/sq_cli/revoke.rs @@ -176,7 +176,7 @@ certificate's creation time", then it will ignore the signature. The notation is marked as \ being human readable." )] - pub notation: Option>, + pub notation: Vec, #[clap( short = 'B', long, @@ -330,7 +330,7 @@ certificate's creation time", then it will ignore the signature. The notation is marked as \ being human readable." )] - pub notation: Option>, + pub notation: Vec, #[clap( short = 'B', long, @@ -451,7 +451,7 @@ certificate's creation time", then it will ignore the signature. The notation is marked as \ being human readable." )] - pub notation: Option>, + pub notation: Vec, #[clap( short = 'B', long, diff --git a/src/sq_cli/sign.rs b/src/sq_cli/sign.rs index 74435121..1651b250 100644 --- a/src/sq_cli/sign.rs +++ b/src/sq_cli/sign.rs @@ -115,5 +115,5 @@ pub struct Command { // TODO: Is there a better way to express that one notation consists of two arguments, and // there may be multiple notations? Like something like Vec<(String, String)>. // TODO: Also, no need for the Option - pub notation: Option>, + pub notation: Vec, }