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/commands/mod.rs | |
parent | 50139c3f7d31aa8207688ef62aa2224d6c0de4de (diff) |
tool: Implement compression and padding.
Diffstat (limited to 'tool/src/commands/mod.rs')
-rw-r--r-- | tool/src/commands/mod.rs | 25 |
1 files changed, 23 insertions, 2 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( |