Move the sign subcommand's dispatcher to its own module
This commit is contained in:
parent
ea2feac6b1
commit
65a3b9da98
@ -45,7 +45,6 @@ pub mod autocrypt;
|
|||||||
pub mod decrypt;
|
pub mod decrypt;
|
||||||
pub mod encrypt;
|
pub mod encrypt;
|
||||||
pub mod sign;
|
pub mod sign;
|
||||||
pub use self::sign::sign;
|
|
||||||
pub mod dump;
|
pub mod dump;
|
||||||
pub use self::dump::dump;
|
pub use self::dump::dump;
|
||||||
mod inspect;
|
mod inspect;
|
||||||
|
@ -19,10 +19,63 @@ use openpgp::serialize::stream::{
|
|||||||
Message, Armorer, Signer, LiteralWriter,
|
Message, Armorer, Signer, LiteralWriter,
|
||||||
};
|
};
|
||||||
use openpgp::types::SignatureType;
|
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::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, ¬ations)?;
|
||||||
|
} else {
|
||||||
|
sign(SignOpts {
|
||||||
|
config,
|
||||||
|
private_key_store,
|
||||||
|
input: &mut input,
|
||||||
|
output_path: output,
|
||||||
|
secrets,
|
||||||
|
detached,
|
||||||
|
binary,
|
||||||
|
append,
|
||||||
|
notarize,
|
||||||
|
time,
|
||||||
|
notations: ¬ations
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub struct SignOpts<'a, 'certdb> {
|
pub struct SignOpts<'a, 'certdb> {
|
||||||
pub config: Config<'certdb>,
|
pub config: Config<'certdb>,
|
||||||
|
44
src/sq.rs
44
src/sq.rs
@ -7,7 +7,6 @@
|
|||||||
#![doc = include_str!(concat!(env!("OUT_DIR"), "/sq-usage.md"))]
|
#![doc = include_str!(concat!(env!("OUT_DIR"), "/sq-usage.md"))]
|
||||||
|
|
||||||
use anyhow::Context as _;
|
use anyhow::Context as _;
|
||||||
use sq_cli::types::FileOrStdin;
|
|
||||||
use is_terminal::IsTerminal;
|
use is_terminal::IsTerminal;
|
||||||
|
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
@ -1052,48 +1051,9 @@ fn main() -> Result<()> {
|
|||||||
commands::encrypt::dispatch(config, command)?
|
commands::encrypt::dispatch(config, command)?
|
||||||
},
|
},
|
||||||
SqSubcommands::Sign(command) => {
|
SqSubcommands::Sign(command) => {
|
||||||
let mut input = command.input.open()?;
|
commands::sign::dispatch(config, command)?
|
||||||
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, ¬ations)?;
|
|
||||||
} else {
|
|
||||||
commands::sign(commands::sign::SignOpts {
|
|
||||||
config,
|
|
||||||
private_key_store,
|
|
||||||
input: &mut input,
|
|
||||||
output_path: output,
|
|
||||||
secrets,
|
|
||||||
detached,
|
|
||||||
binary,
|
|
||||||
append,
|
|
||||||
notarize,
|
|
||||||
time,
|
|
||||||
notations: ¬ations
|
|
||||||
})?;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
SqSubcommands::Verify(command) => {
|
SqSubcommands::Verify(command) => {
|
||||||
let mut input = command.input.open()?;
|
let mut input = command.input.open()?;
|
||||||
let mut output = command.output.create_safe(config.force)?;
|
let mut output = command.output.create_safe(config.force)?;
|
||||||
|
@ -25,7 +25,7 @@ pub mod keyserver;
|
|||||||
pub mod link;
|
pub mod link;
|
||||||
mod output_versions;
|
mod output_versions;
|
||||||
pub mod packet;
|
pub mod packet;
|
||||||
mod sign;
|
pub mod sign;
|
||||||
mod verify;
|
mod verify;
|
||||||
pub mod wkd;
|
pub mod wkd;
|
||||||
pub mod wot;
|
pub mod wot;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user