summaryrefslogtreecommitdiffstats
path: root/ipc/examples/gpg-agent-sign.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ipc/examples/gpg-agent-sign.rs')
-rw-r--r--ipc/examples/gpg-agent-sign.rs54
1 files changed, 39 insertions, 15 deletions
diff --git a/ipc/examples/gpg-agent-sign.rs b/ipc/examples/gpg-agent-sign.rs
index b3204ec9..6e27c239 100644
--- a/ipc/examples/gpg-agent-sign.rs
+++ b/ipc/examples/gpg-agent-sign.rs
@@ -1,6 +1,11 @@
/// Signs data using the openpgp crate and secrets in gpg-agent.
use std::io;
+use std::path::PathBuf;
+
+use clap::CommandFactory;
+use clap::FromArgMatches;
+use clap::Parser;
use sequoia_openpgp as openpgp;
use sequoia_ipc as ipc;
@@ -10,30 +15,49 @@ use openpgp::serialize::stream::{Armorer, Message, LiteralWriter, Signer};
use openpgp::policy::StandardPolicy as P;
use ipc::gnupg::{Context, KeyPair};
+/// Defines the CLI.
+#[derive(Parser, Debug)]
+#[clap(
+ name = "gpg-agent-sign",
+ about = "Connects to gpg-agent and creates a dummy signature.",
+)]
+pub struct Cli {
+ #[clap(
+ long,
+ value_name = "PATH",
+ env = "GNUPGHOME",
+ help = "Use this GnuPG home directory, default: $GNUPGHOME",
+ )]
+ homedir: Option<PathBuf>,
+
+ #[clap(
+ long,
+ value_name = "CERT",
+ help = "Public part of the secret keys managed by gpg-agent",
+ required = true,
+ )]
+ cert: Vec<PathBuf>,
+}
+
fn main() -> openpgp::Result<()> {
let p = &P::new();
- let matches = clap::App::new("gpg-agent-sign")
- .version(env!("CARGO_PKG_VERSION"))
- .about("Connects to gpg-agent and creates a dummy signature.")
- .arg(clap::Arg::with_name("homedir").value_name("PATH")
- .long("homedir")
- .help("Use this GnuPG home directory, default: $GNUPGHOME"))
- .arg(clap::Arg::with_name("cert").value_name("Cert")
- .required(true)
- .multiple(true)
- .help("Public part of the secret keys managed by gpg-agent"))
- .get_matches();
-
- let ctx = if let Some(homedir) = matches.value_of("homedir") {
+ let version = format!(
+ "{} (sequoia-openpgp {}, using {})",
+ env!("CARGO_PKG_VERSION"),
+ sequoia_openpgp::VERSION,
+ sequoia_openpgp::crypto::backend());
+ let cli = Cli::command().version(version);
+ let matches = Cli::from_arg_matches(&cli.get_matches())?;
+
+ let ctx = if let Some(homedir) = matches.homedir {
Context::with_homedir(homedir)?
} else {
Context::new()?
};
// Read the Certs from the given files.
- let certs =
- matches.values_of("cert").expect("required").map(
+ let certs = matches.cert.into_iter().map(
openpgp::Cert::from_file
).collect::<Result<Vec<_>, _>>()?;