Cipher

Enum Cipher 

Source
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], ) -> 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.

Source

pub fn generate_random_key(cipher_algo: Algorithm) -> Result<Vec<u8>, Error>

Source

pub fn generate_random_iv() -> Result<Vec<u8>, Error>

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§

§

impl Freeze for Cipher

§

impl RefUnwindSafe for Cipher

§

impl Send for Cipher

§

impl Sync for Cipher

§

impl Unpin for Cipher

§

impl UnwindSafe for Cipher

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.