diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-09-02 15:40:46 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-09-02 15:40:46 +0200 |
commit | 1cef3a13b4f96fbd02ed7914ff145f112d33355d (patch) | |
tree | ad3abf930667d987a927843ff9e5b0beb35e96ad /tool/src | |
parent | 50139c3f7d31aa8207688ef62aa2224d6c0de4de (diff) |
tool: Implement compression and padding.
Diffstat (limited to 'tool/src')
-rw-r--r-- | tool/src/commands/mod.rs | 25 | ||||
-rw-r--r-- | tool/src/sq-usage.rs | 2 | ||||
-rw-r--r-- | tool/src/sq.rs | 3 | ||||
-rw-r--r-- | tool/src/sq_cli.rs | 10 |
4 files changed, 36 insertions, 4 deletions
diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs index 229a6854..0db911ce 100644 --- a/tool/src/commands/mod.rs +++ b/tool/src/commands/mod.rs @@ -8,7 +8,10 @@ use rpassword; extern crate sequoia_openpgp as openpgp; use sequoia_core::Context; -use crate::openpgp::constants::DataFormat; +use crate::openpgp::constants::{ + CompressionAlgorithm, + DataFormat, +}; use crate::openpgp::crypto; use crate::openpgp::{TPK, KeyID, Result}; use crate::openpgp::packet::prelude::*; @@ -22,6 +25,11 @@ use crate::openpgp::parse::stream::{ }; use crate::openpgp::serialize::stream::{ Message, Signer, LiteralWriter, Encryptor, EncryptionMode, + Compressor, +}; +use crate::openpgp::serialize::padding::{ + Padder, + padme, }; extern crate sequoia_store as store; @@ -80,7 +88,8 @@ fn get_signing_keys(tpks: &[openpgp::TPK]) pub fn encrypt(store: &mut store::Store, input: &mut io::Read, output: &mut io::Write, npasswords: usize, recipients: Vec<&str>, - mut tpks: Vec<openpgp::TPK>, signers: Vec<openpgp::TPK>) + mut tpks: Vec<openpgp::TPK>, signers: Vec<openpgp::TPK>, + compression: &str) -> Result<()> { for r in recipients { tpks.push(store.lookup(r).context("No such key found")?.tpk()?); @@ -114,6 +123,18 @@ pub fn encrypt(store: &mut store::Store, None, None) .context("Failed to create encryptor")?; + match compression { + "none" => (), + "pad" => sink = Padder::new(sink, padme)?, + "zip" => + sink = Compressor::new(sink, CompressionAlgorithm::Zip, None)?, + "zlib" => + sink = Compressor::new(sink, CompressionAlgorithm::Zlib, None)?, + "bzip2" => + sink = Compressor::new(sink, CompressionAlgorithm::BZip2, None)?, + _ => unreachable!("all possible choices are handled") + } + // Optionally sign message. if ! signers.is_empty() { sink = Signer::with_intended_recipients( diff --git a/tool/src/sq-usage.rs b/tool/src/sq-usage.rs index 0b25be37..c5580112 100644 --- a/tool/src/sq-usage.rs +++ b/tool/src/sq-usage.rs @@ -76,6 +76,8 @@ //! -V, --version Prints version information //! //! OPTIONS: +//! --compression <KIND> Selects compression scheme to use [default: pad] [possible values: none, +//! pad, zip, zlib, bzip2] //! -o, --output <FILE> Sets the output file to use //! -r, --recipient <LABEL>... Recipient to encrypt for (can be given multiple times) //! --recipient-key-file <TPK-FILE>... Recipient to encrypt for, given as a file (can be given multiple times) diff --git a/tool/src/sq.rs b/tool/src/sq.rs index a87c176f..9962a0a4 100644 --- a/tool/src/sq.rs +++ b/tool/src/sq.rs @@ -208,7 +208,8 @@ fn real_main() -> Result<(), failure::Error> { .unwrap_or(Ok(vec![]))?; commands::encrypt(&mut store, &mut input, &mut output, m.occurrences_of("symmetric") as usize, - recipients, additional_tpks, additional_secrets)?; + recipients, additional_tpks, additional_secrets, + m.value_of("compression").expect("has default"))?; }, ("sign", Some(m)) => { let mut input = open_or_stdin(m.value_of("input"))?; diff --git a/tool/src/sq_cli.rs b/tool/src/sq_cli.rs index 6042efcb..feb9d755 100644 --- a/tool/src/sq_cli.rs +++ b/tool/src/sq_cli.rs @@ -111,7 +111,15 @@ pub fn build() -> App<'static, 'static> { .short("s") .multiple(true) .help("Encrypt with a password \ - (can be given multiple times)"))) + (can be given multiple times)")) + .arg(Arg::with_name("compression") + .value_name("KIND") + .long("compression") + .possible_values(&["none", "pad", "zip", "zlib", + "bzip2"]) + .default_value("pad") + .help("Selects compression scheme to use"))) + .subcommand(SubCommand::with_name("sign") .display_order(25) .about("Signs a message") |