Enum DecryptionStreams

Source
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§

Implementations§

Source§

impl DecryptionStreams

Source

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();
Source

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.

Source

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.

Source

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);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V