src/backup/crypt_config.rs: new helper data_crypter to get openssl Crypter

This commit is contained in:
Dietmar Maurer 2019-08-12 10:06:51 +02:00
parent 7776becf5d
commit c57ec43a53

View File

@ -82,6 +82,12 @@ impl CryptConfig {
tag tag
} }
pub fn data_crypter(&self, iv: &[u8; 16]) -> Result<Crypter, Error> {
let mut crypter = openssl::symm::Crypter::new(self.cipher, Mode::Encrypt, &self.enc_key, Some(iv))?;
crypter.aad_update(b"")?; //??
Ok(crypter)
}
/// Encrypt data using a random 16 byte IV. /// Encrypt data using a random 16 byte IV.
/// ///
/// Writes encrypted data to ``output``, Return the used IV and computed MAC. /// Writes encrypted data to ``output``, Return the used IV and computed MAC.
@ -96,8 +102,7 @@ impl CryptConfig {
let mut tag = [0u8; 16]; let mut tag = [0u8; 16];
let mut c = Crypter::new(self.cipher, Mode::Encrypt, &self.enc_key, Some(&iv))?; let mut c = self.data_crypter(&iv)?;
c.aad_update(b"")?; //??
const BUFFER_SIZE: usize = 32*1024; const BUFFER_SIZE: usize = 32*1024;
@ -139,8 +144,7 @@ impl CryptConfig {
let mut decompressor = zstd::stream::write::Decoder::new(dec)?; let mut decompressor = zstd::stream::write::Decoder::new(dec)?;
let mut c = Crypter::new(self.cipher, Mode::Decrypt, &self.enc_key, Some(iv))?; let mut c = self.data_crypter(iv)?;
c.aad_update(b"")?; //??
const BUFFER_SIZE: usize = 32*1024; const BUFFER_SIZE: usize = 32*1024;