pub struct Manager<'k> {
pub kms_manager: &'k Manager,
pub kms_key_id: String,
/* private fields */
}
Expand description
Implements envelope encryption manager.
Fields§
§kms_manager: &'k Manager
§kms_key_id: String
Implementations§
Source§impl<'k> Manager<'k>
impl<'k> Manager<'k>
Sourcepub fn new(
kms_manager: &'k Manager,
kms_key_id: String,
aad_tag: String,
) -> Self
pub fn new( kms_manager: &'k Manager, kms_key_id: String, aad_tag: String, ) -> Self
Creates a new envelope encryption manager.
Sourcepub async fn seal_aes_256(&self, d: &[u8]) -> Result<Vec<u8>>
pub async fn seal_aes_256(&self, d: &[u8]) -> Result<Vec<u8>>
Envelope-encrypts the data using AWS KMS data-encryption key (DEK) and “AES_256_GCM” because kms:Encrypt can only encrypt 4 KiB.
The encrypted data are aligned as below: [ Nonce bytes “length” ][ DEK.ciphertext “length” ][ Nonce bytes ][ DEK.ciphertext ][ data ciphertext ]
ref. https://docs.aws.amazon.com/kms/latest/APIReference/API_Decrypt.html
Sourcepub async fn unseal_aes_256(&self, d: &[u8]) -> Result<Vec<u8>>
pub async fn unseal_aes_256(&self, d: &[u8]) -> Result<Vec<u8>>
Envelope-decrypts using KMS DEK and “AES_256_GCM”.
Assume the input (ciphertext) data are packed in the order of: [ Nonce bytes “length” ][ DEK.ciphertext “length” ][ Nonce bytes ][ DEK.ciphertext ][ data ciphertext ]
ref. https://docs.aws.amazon.com/kms/latest/APIReference/API_Encrypt.html ref. https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateDataKey.html
Sourcepub async fn seal_aes_256_file(
&self,
src_file: &str,
dst_file: &str,
) -> Result<()>
pub async fn seal_aes_256_file( &self, src_file: &str, dst_file: &str, ) -> Result<()>
Envelope-encrypts data from a file and save the ciphertext to the other file.
“If a single piece of data must be accessible from more than one task concurrently, then it must be shared using synchronization primitives such as Arc.” ref. https://tokio.rs/tokio/tutorial/spawning
Sourcepub async fn unseal_aes_256_file(
&self,
src_file: &str,
dst_file: &str,
) -> Result<()>
pub async fn unseal_aes_256_file( &self, src_file: &str, dst_file: &str, ) -> Result<()>
Envelope-decrypts data from a file and save the plaintext to the other file.
Sourcepub async fn compress_seal(&self, src_file: &str, dst_file: &str) -> Result<()>
pub async fn compress_seal(&self, src_file: &str, dst_file: &str) -> Result<()>
Compresses the source file (“src_file”) and envelope-encrypts to “dst_file”. The compression uses “zstd”. The encryption uses AES 256.
Sourcepub async fn unseal_decompress(
&self,
src_file: &str,
dst_file: &str,
) -> Result<()>
pub async fn unseal_decompress( &self, src_file: &str, dst_file: &str, ) -> Result<()>
Reverse of “compress_seal”. The decompression uses “zstd”. The decryption uses AES 256.
Trait Implementations§
Auto Trait Implementations§
impl<'k> Freeze for Manager<'k>
impl<'k> !RefUnwindSafe for Manager<'k>
impl<'k> Send for Manager<'k>
impl<'k> Sync for Manager<'k>
impl<'k> Unpin for Manager<'k>
impl<'k> !UnwindSafe for Manager<'k>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more