pub struct EnvelopeEncryptor { /* private fields */ }Expand description
Envelope encryptor with key rotation support.
§Ciphertext Format
[envelope_version: 1 byte][key_version: 4 bytes][cipher_data: variable]The cipher_data contains the nonce, ciphertext, and authentication tag as produced by the underlying cipher.
Implementations§
Source§impl EnvelopeEncryptor
impl EnvelopeEncryptor
Sourcepub fn new(key: EncryptionKey) -> Self
pub fn new(key: EncryptionKey) -> Self
Create a new envelope encryptor with a single key.
Sourcepub fn with_key_ring(key_ring: KeyRing) -> Self
pub fn with_key_ring(key_ring: KeyRing) -> Self
Create from an existing key ring.
Sourcepub fn key_ring_mut(&mut self) -> &mut KeyRing
pub fn key_ring_mut(&mut self) -> &mut KeyRing
Get a mutable reference to the key ring.
Sourcepub fn rotate_key(&mut self, new_key: EncryptionKey) -> u32
pub fn rotate_key(&mut self, new_key: EncryptionKey) -> u32
Rotate to a new key.
Sourcepub fn encrypt(
&self,
plaintext: &[u8],
associated_data: Option<&[u8]>,
) -> CryptoResult<Vec<u8>>
pub fn encrypt( &self, plaintext: &[u8], associated_data: Option<&[u8]>, ) -> CryptoResult<Vec<u8>>
Encrypt data with the active key.
Sourcepub fn decrypt(
&self,
ciphertext: &[u8],
associated_data: Option<&[u8]>,
) -> CryptoResult<Vec<u8>>
pub fn decrypt( &self, ciphertext: &[u8], associated_data: Option<&[u8]>, ) -> CryptoResult<Vec<u8>>
Decrypt data using the key version from the envelope.
Sourcepub fn re_encrypt(
&self,
ciphertext: &[u8],
associated_data: Option<&[u8]>,
) -> CryptoResult<Vec<u8>>
pub fn re_encrypt( &self, ciphertext: &[u8], associated_data: Option<&[u8]>, ) -> CryptoResult<Vec<u8>>
Re-encrypt data with the current active key.
Useful during key rotation to migrate old data to new keys.
Sourcepub fn uses_active_key(&self, ciphertext: &[u8]) -> CryptoResult<bool>
pub fn uses_active_key(&self, ciphertext: &[u8]) -> CryptoResult<bool>
Check if ciphertext uses the active key.
Sourcepub fn get_key_version(&self, ciphertext: &[u8]) -> CryptoResult<u32>
pub fn get_key_version(&self, ciphertext: &[u8]) -> CryptoResult<u32>
Get the key version from ciphertext.
Trait Implementations§
Source§impl DataEncryptor for EnvelopeEncryptor
Available on crate feature aes only.
impl DataEncryptor for EnvelopeEncryptor
Available on crate feature
aes only.Source§fn encrypt_data<T: Serialize>(&self, data: &T) -> CryptoResult<Vec<u8>>
fn encrypt_data<T: Serialize>(&self, data: &T) -> CryptoResult<Vec<u8>>
Encrypt a serializable value.
Source§fn decrypt_data<T: DeserializeOwned>(
&self,
ciphertext: &[u8],
) -> CryptoResult<T>
fn decrypt_data<T: DeserializeOwned>( &self, ciphertext: &[u8], ) -> CryptoResult<T>
Decrypt to a deserializable value.
Auto Trait Implementations§
impl Freeze for EnvelopeEncryptor
impl RefUnwindSafe for EnvelopeEncryptor
impl Send for EnvelopeEncryptor
impl Sync for EnvelopeEncryptor
impl Unpin for EnvelopeEncryptor
impl UnsafeUnpin for EnvelopeEncryptor
impl UnwindSafe for EnvelopeEncryptor
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