diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2022-06-30 15:03:49 +0200 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2022-07-05 13:57:05 +0200 |
commit | 9c20d3604377c69b8032a0d50ce2a4327c9df899 (patch) | |
tree | 20b024f940fb48b5f03d5afe225519a78e66a9c5 /sq | |
parent | c862dc82d956dffd10cda0a1f0d8451188259828 (diff) |
sq: Adapt key password to clap 3's derive API.
Diffstat (limited to 'sq')
-rw-r--r-- | sq/src/commands/key.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/sq/src/commands/key.rs b/sq/src/commands/key.rs index 47ed82b3..5de4599c 100644 --- a/sq/src/commands/key.rs +++ b/sq/src/commands/key.rs @@ -25,6 +25,7 @@ use crate::parse_duration; use crate::decrypt_key; use crate::sq_cli::KeyGenerateCommand; +use crate::sq_cli::KeyPasswordCommand; use clap::FromArgMatches; pub fn dispatch(config: Config, m: &clap::ArgMatches) -> Result<()> { @@ -33,13 +34,17 @@ pub fn dispatch(config: Config, m: &clap::ArgMatches) -> Result<()> { let c = KeyGenerateCommand::from_arg_matches(m)?; generate(config, c)? }, - Some(("password", m)) => password(config, m)?, + Some(("password", m)) => { + let c = KeyPasswordCommand::from_arg_matches(m)?; + password(config, c)? + }, Some(("extract-cert", m)) => extract_cert(config, m)?, Some(("adopt", m)) => adopt(config, m)?, Some(("attest-certifications", m)) => attest_certifications(config, m)?, _ => unreachable!(), } + Ok(()) } @@ -226,8 +231,8 @@ fn generate(config: Config, command: KeyGenerateCommand) -> Result<()> { Ok(()) } -fn password(config: Config, m: &ArgMatches) -> Result<()> { - let input = open_or_stdin(m.value_of("input"))?; +fn password(config: Config, command: KeyPasswordCommand) -> Result<()> { + let input = open_or_stdin(command.io.input.as_deref())?; let key = Cert::from_reader(input)?; if ! key.is_tsk() { @@ -250,7 +255,7 @@ fn password(config: Config, m: &ArgMatches) -> Result<()> { assert_eq!(key.keys().secret().count(), key.keys().unencrypted_secret().count()); - let new_password = if m.is_present("clear") { + let new_password = if command.clear { None } else { let prompt_0 = @@ -285,8 +290,8 @@ fn password(config: Config, m: &ArgMatches) -> Result<()> { key = key.insert_packets(encrypted)?; } - let mut output = config.create_or_stdout_safe(m.value_of("output"))?; - if m.is_present("binary") { + let mut output = config.create_or_stdout_safe(command.io.output.as_deref())?; + if command.binary { key.as_tsk().serialize(&mut output)?; } else { key.as_tsk().armored().serialize(&mut output)?; |