pub enum Cipher {
None,
Aes128Xts(Cipher),
Aes256Xts(Cipher),
Aes256Gcm(Cipher),
}Expand description
Cipher object to encrypt/decrypt data.
Variants§
Implementations§
Source§impl Cipher
impl Cipher
Sourcepub fn encrypt<'a>(
&self,
key: &[u8],
iv: Option<&[u8]>,
data: &'a [u8],
) -> Result<Cow<'a, [u8]>, Error>
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.
Sourcepub fn decrypt(
&self,
key: &[u8],
iv: Option<&[u8]>,
data: &[u8],
) -> Result<Vec<u8>, Error>
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.
Sourcepub fn encrypt_aead(
&self,
key: &[u8],
iv: Option<&[u8]>,
data: &[u8],
tag: &mut [u8],
) -> Result<Vec<u8>, Error>
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.
Sourcepub fn decrypt_aead(
&self,
key: &[u8],
iv: Option<&[u8]>,
data: &[u8],
tag: &[u8],
) -> Result<Vec<u8>, Error>
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.
Sourcepub fn encrypted_size(&self, plaintext_size: usize) -> usize
pub fn encrypted_size(&self, plaintext_size: usize) -> usize
Get size of ciphertext from size of plaintext.
Sourcepub fn tweak_key_for_xts(key: &[u8]) -> Cow<'_, [u8]>
pub fn tweak_key_for_xts(key: &[u8]) -> Cow<'_, [u8]>
Tweak key for XTS mode.
pub fn generate_random_key(cipher_algo: Algorithm) -> Result<Vec<u8>, Error>
pub fn generate_random_iv() -> Result<Vec<u8>, Error>
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more