blob: 8f2d7415b1ab7a520221223830d09bd26252328f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
/// Connects to and sends commands to gpg-agent.
use futures::StreamExt;
use sequoia_ipc as ipc;
use crate::ipc::gnupg::{Context, Agent};
fn main() {
let matches = clap::App::new("gpg-agent-client")
.version(env!("CARGO_PKG_VERSION"))
.about("Connects to and sends commands to gpg-agent.")
.arg(clap::Arg::with_name("homedir").value_name("PATH")
.long("homedir")
.help("Use this GnuPG home directory, default: $GNUPGHOME"))
.arg(clap::Arg::with_name("commands").value_name("COMMAND")
.required(true)
.multiple(true)
.help("Commands to send to the server"))
.get_matches();
let ctx = if let Some(homedir) = matches.value_of("homedir") {
Context::with_homedir(homedir).unwrap()
} else {
Context::new().unwrap()
};
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let mut agent = Agent::connect(&ctx).await.unwrap();
for command in matches.values_of("commands").unwrap() {
eprintln!("> {}", command);
agent.send(command).unwrap();
while let Some(response) = agent.next().await {
eprintln!("< {:?}", response);
}
}
});
}
|