summaryrefslogtreecommitdiffstats
path: root/tool
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-04-10 18:05:57 +0200
committerJustus Winter <justus@sequoia-pgp.org>2019-04-24 12:28:45 +0200
commit0bd155dbd8faf84507b62553b6a5c9e6936fe49f (patch)
treef135947ff7a4afe9443baf6e6d9d4c86cd5352eb /tool
parent0f8fa3961c60b575765e5aec598ac552b78b7e17 (diff)
openpgp: Implement creation and serialization of Autocrypt headers.
Diffstat (limited to 'tool')
-rw-r--r--tool/src/sq-usage.rs27
-rw-r--r--tool/src/sq.rs26
-rw-r--r--tool/src/sq_cli.rs23
3 files changed, 72 insertions, 4 deletions
diff --git a/tool/src/sq-usage.rs b/tool/src/sq-usage.rs
index 6e931570..f3159937 100644
--- a/tool/src/sq-usage.rs
+++ b/tool/src/sq-usage.rs
@@ -340,8 +340,9 @@
//! -V, --version Prints version information
//!
//! SUBCOMMANDS:
-//! decode Converts Autocrypt-encoded keys to OpenPGP TPKs
-//! help Prints this message or the help of the given subcommand(s)
+//! decode Converts Autocrypt-encoded keys to OpenPGP TPKs
+//! encode-sender Encodes the senders' OpenPGP TPKs into an Autocrypt header
+//! help Prints this message or the help of the given subcommand(s)
//! ```
//!
//! ### Subcommand autocrypt decode
@@ -363,6 +364,28 @@
//! <FILE> Sets the input file to use
//! ```
//!
+//! ### Subcommand autocrypt encode-sender
+//!
+//! ```text
+//! Encodes the senders' OpenPGP TPKs into an Autocrypt header
+//!
+//! USAGE:
+//! sq autocrypt encode-sender [OPTIONS] [FILE]
+//!
+//! FLAGS:
+//! -h, --help Prints help information
+//! -V, --version Prints version information
+//!
+//! OPTIONS:
+//! --address <address> Select userid to use. [default: primary userid]
+//! -o, --output <FILE> Sets the output file to use
+//! --prefer-encrypt <prefer-encrypt> Sets the prefer-encrypt attribute [default: nopreference] [possible
+//! values: nopreference, mutual]
+//!
+//! ARGS:
+//! <FILE> Sets the input file to use
+//! ```
+//!
//! ## Subcommand dearmor
//!
//! ```text
diff --git a/tool/src/sq.rs b/tool/src/sq.rs
index c82698e3..1902e8bd 100644
--- a/tool/src/sq.rs
+++ b/tool/src/sq.rs
@@ -221,7 +221,31 @@ fn real_main() -> Result<(), failure::Error> {
tpk.serialize(&mut filter)?;
}
}
- }
+ },
+ ("encode-sender", Some(m)) => {
+ let mut input = open_or_stdin(m.value_of("input"))?;
+ let mut output = create_or_stdout(m.value_of("output"),
+ force)?;
+ let tpk = TPK::from_reader(input)?;
+ let addr = m.value_of("address").map(|a| a.to_string())
+ .or_else(|| {
+ if let Some(Ok(Some(a))) =
+ tpk.userids().nth(0).map(|u| u.userid().address())
+ {
+ Some(a)
+ } else {
+ None
+ }
+ });
+ let ac = autocrypt::AutocryptHeader::new_sender(
+ &tpk,
+ &addr.ok_or(failure::err_msg(
+ "No well-formed primary userid found, use \
+ --address to specify one"))?,
+ m.value_of("prefer-encrypt").expect("has default"))?;
+ write!(&mut output, "Autocrypt: ")?;
+ ac.serialize(&mut output)?;
+ },
_ => unreachable!(),
}
},
diff --git a/tool/src/sq_cli.rs b/tool/src/sq_cli.rs
index bfa64601..a75d1349 100644
--- a/tool/src/sq_cli.rs
+++ b/tool/src/sq_cli.rs
@@ -211,7 +211,28 @@ pub fn build() -> App<'static, 'static> {
.arg(Arg::with_name("output").value_name("FILE")
.long("output")
.short("o")
- .help("Sets the output file to use"))))
+ .help("Sets the output file to use")))
+ .subcommand(SubCommand::with_name("encode-sender")
+ .about("Encodes the senders' OpenPGP TPKs into \
+ an Autocrypt header")
+ .arg(Arg::with_name("input").value_name("FILE")
+ .help("Sets the input file to use"))
+ .arg(Arg::with_name("output").value_name("FILE")
+ .long("output")
+ .short("o")
+ .help("Sets the output file to use"))
+ .arg(Arg::with_name("address")
+ .long("address")
+ .takes_value(true)
+ .help("Select userid to use. \
+ [default: primary userid]"))
+ .arg(Arg::with_name("prefer-encrypt")
+ .long("prefer-encrypt")
+ .possible_values(&["nopreference",
+ "mutual"])
+ .default_value("nopreference")
+ .help("Sets the prefer-encrypt \
+ attribute"))))
.subcommand(SubCommand::with_name("inspect")
.about("Inspects a sequence of OpenPGP packets")
.arg(Arg::with_name("input").value_name("FILE")