Enum Ciphers

Source
pub enum Ciphers {
    Aes256Gcm(Box<Aes256Gcm>),
    XChaCha(Box<XChaCha20Poly1305>),
    DeoxysII(Box<DeoxysII256>),
}
Expand description

This enum defines all possible cipher types, for each AEAD that is supported by dexios-core

Variants§

§

Aes256Gcm(Box<Aes256Gcm>)

§

XChaCha(Box<XChaCha20Poly1305>)

§

DeoxysII(Box<DeoxysII256>)

Implementations§

Source§

impl Ciphers

Source

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

This can be used to quickly initialise a Cipher

The returned Cipher can be used for both encryption and decryption

You just need to provide the argon2id/balloon hashed key, and the algorithm to use

§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 cipher = Ciphers::initialize(key, &Algorithm::XChaCha20Poly1305).unwrap();
Source

pub fn encrypt<'msg, 'aad>( &self, nonce: &[u8], plaintext: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>>

This can be used to encrypt data with a given Ciphers object

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

Source

pub fn encrypt_in_place( &self, nonce: &[u8], aad: &[u8], buffer: &mut dyn Buffer, ) -> Result<(), Error>

Source

pub fn decrypt<'msg, 'aad>( &self, nonce: &[u8], ciphertext: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>>

This can be used to decrypt data with a given Ciphers object

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

NOTE: The data will not decrypt successfully if an AAD was provided for encryption, but is not present/has been modified while decrypting

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