Enum EncryptionStreams

Source
pub enum EncryptionStreams {
    Aes256Gcm(Box<EncryptorLE31<Aes256Gcm>>),
    XChaCha20Poly1305(Box<EncryptorLE31<XChaCha20Poly1305>>),
    DeoxysII256(Box<EncryptorLE31<DeoxysII256>>),
}
Expand description

This enum contains streams for that are used solely for encryption

It has definitions for all AEADs supported by dexios-core

Variants§

Implementations§

Source§

impl EncryptionStreams

Source

pub fn initialize( key: Protected<[u8; 32]>, nonce: &[u8], algorithm: &Algorithm, ) -> Result<Self>

This method can be used to quickly create an EncryptionStreams object

It requies a 32-byte hashed key, which will be dropped once the stream has been initialized

It requires a pre-generated nonce, which you may generate with gen_nonce()

If the nonce length is not exact, you will receive an error.

It will create the stream with the specified algorithm, and it will also generate the appropriate nonce

The EncryptionStreams object is 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();

let nonce = gen_nonce(&Algorithm::XChaCha20Poly1305, &Mode::StreamMode);
let encrypt_stream = EncryptionStreams::initialize(key, &nonce, &Algorithm::XChaCha20Poly1305).unwrap();
Source

pub fn encrypt_next<'msg, 'aad>( &mut self, payload: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>>

This is used for encrypting the next block of data in streaming mode

It requires either some plaintext, or an aead::Payload (that contains the plaintext and the AAD)

Source

pub fn encrypt_last<'msg, 'aad>( self, payload: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>>

This is used for encrypting 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)

Source

pub fn encrypt_file( self, reader: &mut impl Read, writer: &mut impl Write, aad: &[u8], ) -> Result<()>

This is a convenience function for reading from a reader, encrypting, 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.

You are free to use a custom AAD, just ensure that it is present for decryption, or else you will receive an error.

This does not handle writing the header.

§Examples
let mut input_file = File::open("input").unwrap();
let mut output_file = File::create("output.encrypted").unwrap();

// aad should be generated from the header (only for encryption)
let aad = header.serialize().unwrap();

let encrypt_stream = EncryptionStreams::initialize(key, &nonce, &Algorithm::XChaCha20Poly1305).unwrap();
encrypt_stream.encrypt_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