pub enum Cipher {
    None,
    Aes128Xts(Cipher),
    Aes256Xts(Cipher),
    Aes256Gcm(Cipher),
}
Expand description

Cipher object to encrypt/decrypt data.

Variants§

§

None

§

Aes128Xts(Cipher)

§

Aes256Xts(Cipher)

§

Aes256Gcm(Cipher)

Implementations§

source§

impl Cipher

source

pub fn encrypt<'a>( &self, key: &[u8], iv: Option<&[u8]>, data: &'a [u8] ) -> Result<Cow<'a, [u8]>, Error>

Encrypt plaintext with optional IV and return the encrypted data.

For XTS, the caller needs to ensure that the top half of key is not identical to the bottom half of the key, otherwise the encryption will fail.

source

pub fn decrypt( &self, key: &[u8], iv: Option<&[u8]>, data: &[u8], size: usize ) -> Result<Vec<u8>, Error>

Decrypt encrypted data with optional IV and return the decrypted data.

source

pub fn encrypt_aead( &self, key: &[u8], iv: Option<&[u8]>, data: &[u8], tag: &mut [u8] ) -> Result<Vec<u8>, Error>

Encrypt plaintext and return the ciphertext with authentication tag.

source

pub fn decrypt_aead( &self, key: &[u8], iv: Option<&[u8]>, data: &[u8], tag: &[u8] ) -> Result<Vec<u8>, Error>

Decrypt plaintext and return the encrypted data with authentication tag.

source

pub fn tag_size(&self) -> usize

Get size of tag associated with encrypted data.

source

pub fn encrypted_size(&self, plaintext_size: usize) -> usize

Get size of ciphertext from size of plaintext.

source

pub fn tweak_key_for_xts(key: &[u8]) -> Cow<'_, [u8]>

Tweak key for XTS mode.

Trait Implementations§

source§

impl Debug for Cipher

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Cipher

source§

fn default() -> Cipher

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.