summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2021-01-06 12:48:14 +0100
committerJustus Winter <justus@sequoia-pgp.org>2021-01-06 12:48:14 +0100
commit9b8733463737a369f970f787271000d19b696a26 (patch)
tree62ff590696f4a9fff805420acfad38f08419465a
parentc3eed60467ebb02df55d90eecdc08827b2f485c8 (diff)
sq: Implement 'certring list'.
-rw-r--r--sq/src/commands/certring.rs22
-rw-r--r--sq/src/sq-usage.rs17
-rw-r--r--sq/src/sq_cli.rs5
3 files changed, 44 insertions, 0 deletions
diff --git a/sq/src/commands/certring.rs b/sq/src/commands/certring.rs
index d8a08fa3..094861f4 100644
--- a/sq/src/commands/certring.rs
+++ b/sq/src/commands/certring.rs
@@ -34,6 +34,10 @@ pub fn dispatch(m: &clap::ArgMatches, force: bool) -> Result<()> {
join(m.values_of("input"), &mut output)?;
output.finalize()
},
+ ("list", Some(m)) => {
+ let mut input = open_or_stdin(m.value_of("input"))?;
+ list(&mut input)
+ },
("split", Some(m)) => {
let mut input = open_or_stdin(m.value_of("input"))?;
let prefix =
@@ -77,6 +81,24 @@ fn join(inputs: Option<clap::Values>, output: &mut dyn io::Write)
Ok(())
}
+/// Lists certs in a certring.
+fn list(input: &mut (dyn io::Read + Sync + Send))
+ -> Result<()> {
+ for (i, cert) in CertParser::from_reader(input)?.enumerate() {
+ let cert = cert.context("Malformed certificate in certring")?;
+ print!("{}. {:X}", i, cert.fingerprint());
+ // Try to be more helpful by including the first userid in the
+ // listing.
+ if let Some(email) = cert.userids().nth(0)
+ .and_then(|uid| uid.email().unwrap_or(None))
+ {
+ print!(" {}", email);
+ }
+ println!();
+ }
+ Ok(())
+}
+
/// Splits a certring into individual certs.
fn split(input: &mut (dyn io::Read + Sync + Send), prefix: &str)
-> Result<()> {
diff --git a/sq/src/sq-usage.rs b/sq/src/sq-usage.rs
index 7a909bb6..59844351 100644
--- a/sq/src/sq-usage.rs
+++ b/sq/src/sq-usage.rs
@@ -444,6 +444,7 @@
//! SUBCOMMANDS:
//! help Prints this message or the help of the given subcommand(s)
//! join Joins certs into a certring
+//! list Lists certs in a certring
//! split Splits a certring into individual certs
//! ```
//!
@@ -467,6 +468,22 @@
//! <FILE>... Sets the input files to use
//! ```
//!
+//! ### Subcommand certring list
+//!
+//! ```text
+//! Lists certs in a certring
+//!
+//! USAGE:
+//! sq certring list [FILE]
+//!
+//! FLAGS:
+//! -h, --help Prints help information
+//! -V, --version Prints version information
+//!
+//! ARGS:
+//! <FILE> Sets the input file to use
+//! ```
+//!
//! ### Subcommand certring split
//!
//! ```text
diff --git a/sq/src/sq_cli.rs b/sq/src/sq_cli.rs
index 6e4428ed..e924b8ab 100644
--- a/sq/src/sq_cli.rs
+++ b/sq/src/sq_cli.rs
@@ -531,6 +531,11 @@ pub fn build() -> App<'static, 'static> {
.short("B")
.help("Don't ASCII-armor the certring")))
.subcommand(
+ SubCommand::with_name("list")
+ .about("Lists certs in a certring")
+ .arg(Arg::with_name("input").value_name("FILE")
+ .help("Sets the input file to use")))
+ .subcommand(
SubCommand::with_name("split")
.about("Splits a certring into individual certs")
.arg(Arg::with_name("input").value_name("FILE")