diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2021-01-28 17:44:17 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2021-01-28 17:44:17 +0100 |
commit | ba10ed512b11684877f011d67d63431ee6926979 (patch) | |
tree | 10c29bc411f2db5b22d34e4c4df9dd0b3b83b687 | |
parent | 76d171f1520cf4ec92138ca85039133224685fd1 (diff) |
sq: Refactor.
-rw-r--r-- | sq/src/commands/key.rs | 19 | ||||
-rw-r--r-- | sq/src/sq.rs | 8 |
2 files changed, 16 insertions, 11 deletions
diff --git a/sq/src/commands/key.rs b/sq/src/commands/key.rs index 3ed69a04..b4c51e65 100644 --- a/sq/src/commands/key.rs +++ b/sq/src/commands/key.rs @@ -25,7 +25,18 @@ use crate::SECONDS_IN_YEAR; use crate::parse_duration; use crate::decrypt_key; -pub fn generate(m: &ArgMatches, force: bool) -> Result<()> { +pub fn dispatch(config: Config, m: &clap::ArgMatches) -> Result<()> { + match m.subcommand() { + ("generate", Some(m)) => generate(m, config.force)?, + ("adopt", Some(m)) => adopt(config, m)?, + ("attest-certifications", Some(m)) => + attest_certifications(config, m)?, + _ => unreachable!(), + } + Ok(()) +} + +fn generate(m: &ArgMatches, force: bool) -> Result<()> { let mut builder = CertBuilder::new(); // User ID @@ -194,7 +205,7 @@ pub fn generate(m: &ArgMatches, force: bool) -> Result<()> { Ok(()) } -pub fn adopt(config: Config, m: &ArgMatches) -> Result<()> { +fn adopt(config: Config, m: &ArgMatches) -> Result<()> { let input = open_or_stdin(m.value_of("certificate"))?; let cert = Cert::from_reader(input)?; let mut wanted: Vec<(KeyHandle, @@ -397,8 +408,8 @@ pub fn adopt(config: Config, m: &ArgMatches) -> Result<()> { Ok(()) } -pub fn attest_certifications(config: Config, m: &ArgMatches) - -> Result<()> { +fn attest_certifications(config: Config, m: &ArgMatches) + -> Result<()> { // XXX: This function has to do some steps manually, because // Sequoia does not expose this functionality because it has not // been standardized yet. diff --git a/sq/src/sq.rs b/sq/src/sq.rs index 5f5467d1..6ba4c675 100644 --- a/sq/src/sq.rs +++ b/sq/src/sq.rs @@ -626,13 +626,7 @@ fn main() -> Result<()> { ("keyserver", Some(m)) => commands::net::dispatch_keyserver(config, m)?, - ("key", Some(m)) => match m.subcommand() { - ("generate", Some(m)) => commands::key::generate(m, force)?, - ("adopt", Some(m)) => commands::key::adopt(config, m)?, - ("attest-certifications", Some(m)) => - commands::key::attest_certifications(config, m)?, - _ => unreachable!(), - }, + ("key", Some(m)) => commands::key::dispatch(config, m)?, #[cfg(feature = "net")] ("wkd", Some(m)) => commands::net::dispatch_wkd(config, m)?, |