pub enum DecryptionStreams {
Aes256Gcm(Box<DecryptorLE31<Aes256Gcm>>),
XChaCha20Poly1305(Box<DecryptorLE31<XChaCha20Poly1305>>),
DeoxysII256(Box<DecryptorLE31<DeoxysII256>>),
}
Expand description
This enum
contains streams for that are used solely for decryption
It has definitions for all AEADs supported by dexios-core
Variants§
Aes256Gcm(Box<DecryptorLE31<Aes256Gcm>>)
XChaCha20Poly1305(Box<DecryptorLE31<XChaCha20Poly1305>>)
DeoxysII256(Box<DecryptorLE31<DeoxysII256>>)
Implementations§
Source§impl DecryptionStreams
impl DecryptionStreams
Sourcepub fn initialize(
key: Protected<[u8; 32]>,
nonce: &[u8],
algorithm: &Algorithm,
) -> Result<Self>
pub fn initialize( key: Protected<[u8; 32]>, nonce: &[u8], algorithm: &Algorithm, ) -> Result<Self>
This method can be used to quickly create an DecryptionStreams
object
It requies a 32-byte hashed key, which will be dropped once the stream has been initialized
It requires the same nonce that was returned upon initializing EncryptionStreams
It will create the stream with the specified algorithm
The DecryptionStreams
object will be returned
§Examples
// obviously the key should contain data, not be an empty vec
let raw_key = Protected::new(vec![0u8; 128]);
let salt = gen_salt();
let key = balloon_hash(raw_key, &salt, &HeaderVersion::V4).unwrap();
// this nonce should be read from somewhere, not generated
let nonce = gen_nonce(&Algorithm::XChaCha20Poly1305, &Mode::StreamMode);
let decrypt_stream = DecryptionStreams::initialize(key, &nonce, &Algorithm::XChaCha20Poly1305).unwrap();
Sourcepub fn decrypt_next<'msg, 'aad>(
&mut self,
payload: impl Into<Payload<'msg, 'aad>>,
) -> Result<Vec<u8>>
pub fn decrypt_next<'msg, 'aad>( &mut self, payload: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>>
This is used for decrypting the next block of data in streaming mode
It requires either some plaintext, or an aead::Payload
(that contains the plaintext and the AAD)
Whatever you provided as AAD while encrypting must be present during decryption, or else you will receive an error.
Sourcepub fn decrypt_last<'msg, 'aad>(
self,
payload: impl Into<Payload<'msg, 'aad>>,
) -> Result<Vec<u8>>
pub fn decrypt_last<'msg, 'aad>( self, payload: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>>
This is used for decrypting the last block of data in streaming mode. It consumes the stream object to prevent further usage.
It requires either some plaintext, or an aead::Payload
(that contains the plaintext and the AAD)
Whatever you provided as AAD while encrypting must be present during decryption, or else you will receive an error.
Sourcepub fn decrypt_file(
self,
reader: &mut impl Read,
writer: &mut impl Write,
aad: &[u8],
) -> Result<()>
pub fn decrypt_file( self, reader: &mut impl Read, writer: &mut impl Write, aad: &[u8], ) -> Result<()>
This is a convenience function for reading from a reader, decrypting, and writing to the writer.
Every single block is provided with the AAD
Valid AAD must be provided if you are using HeaderVersion::V3
and above. It must be empty if the HeaderVersion
is lower. Whatever you provided as AAD while encrypting must be present during decryption, or else you will receive an error.
This does not handle writing the header.
§Examples
let mut input_file = File::open("input.encrypted").unwrap();
let mut output_file = File::create("output").unwrap();
// aad should be retrieved from the `Header` (with `Header::deserialize()`)
let aad = Vec::new();
let decrypt_stream = DecryptionStreams::initialize(key, &nonce, &Algorithm::XChaCha20Poly1305).unwrap();
decrypt_stream.decrypt_file(&mut input_file, &mut output_file, &aad);