Move the sign subcommand's dispatcher to its own module

This commit is contained in:
Neal H. Walfield 2023-10-17 10:55:15 +02:00
parent ea2feac6b1
commit 65a3b9da98
No known key found for this signature in database
GPG Key ID: 6863C9AD5B4D22D3
4 changed files with 59 additions and 47 deletions

View File

@ -45,7 +45,6 @@ pub mod autocrypt;
pub mod decrypt;
pub mod encrypt;
pub mod sign;
pub use self::sign::sign;
pub mod dump;
pub use self::dump::dump;
mod inspect;

View File

@ -19,10 +19,63 @@ use openpgp::serialize::stream::{
Message, Armorer, Signer, LiteralWriter,
};
use openpgp::types::SignatureType;
use crate::Config;
use crate::commands::merge_signatures::merge_signatures;
use crate::load_certs;
use crate::parse_notations;
use crate::sq_cli;
use crate::sq_cli::types::FileOrStdin;
use crate::sq_cli::types::FileOrStdout;
use crate::{
Config,
};
pub fn dispatch(config: Config, command: sq_cli::sign::Command) -> Result<()> {
tracer!(TRACE, "sign::dispatch");
let mut input = command.input.open()?;
let output = &command.output;
let detached = command.detached;
let binary = command.binary;
let append = command.append;
let notarize = command.notarize;
let private_key_store = command.private_key_store.as_deref();
let secrets =
load_certs(command.secret_key_file.iter().map(|s| s.as_ref()))?;
let time = Some(config.time);
let notations = parse_notations(command.notation)?;
if let Some(merge) = command.merge {
let output = output.create_pgp_safe(
config.force,
binary,
armor::Kind::Message,
)?;
let data: FileOrStdin = merge.into();
let mut input2 = data.open()?;
merge_signatures(&mut input, &mut input2, output)?;
} else if command.clearsign {
let output = output.create_safe(config.force)?;
clearsign(config, private_key_store, input, output, secrets,
time, &notations)?;
} else {
sign(SignOpts {
config,
private_key_store,
input: &mut input,
output_path: output,
secrets,
detached,
binary,
append,
notarize,
time,
notations: &notations
})?;
}
Ok(())
}
pub struct SignOpts<'a, 'certdb> {
pub config: Config<'certdb>,

View File

@ -7,7 +7,6 @@
#![doc = include_str!(concat!(env!("OUT_DIR"), "/sq-usage.md"))]
use anyhow::Context as _;
use sq_cli::types::FileOrStdin;
use is_terminal::IsTerminal;
use std::borrow::Borrow;
@ -1052,48 +1051,9 @@ fn main() -> Result<()> {
commands::encrypt::dispatch(config, command)?
},
SqSubcommands::Sign(command) => {
let mut input = command.input.open()?;
let output = &command.output;
let detached = command.detached;
let binary = command.binary;
let append = command.append;
let notarize = command.notarize;
let private_key_store = command.private_key_store.as_deref();
let secrets =
load_certs(command.secret_key_file.iter().map(|s| s.as_ref()))?;
let time = Some(config.time);
let notations = parse_notations(command.notation)?;
if let Some(merge) = command.merge {
let output = output.create_pgp_safe(
config.force,
binary,
armor::Kind::Message,
)?;
let data: FileOrStdin = merge.into();
let mut input2 = data.open()?;
commands::merge_signatures(&mut input, &mut input2, output)?;
} else if command.clearsign {
let output = output.create_safe(config.force)?;
commands::sign::clearsign(config, private_key_store, input, output, secrets,
time, &notations)?;
} else {
commands::sign(commands::sign::SignOpts {
config,
private_key_store,
input: &mut input,
output_path: output,
secrets,
detached,
binary,
append,
notarize,
time,
notations: &notations
})?;
}
commands::sign::dispatch(config, command)?
},
SqSubcommands::Verify(command) => {
let mut input = command.input.open()?;
let mut output = command.output.create_safe(config.force)?;

View File

@ -25,7 +25,7 @@ pub mod keyserver;
pub mod link;
mod output_versions;
pub mod packet;
mod sign;
pub mod sign;
mod verify;
pub mod wkd;
pub mod wot;