pub struct Encryptor { /* private fields */ }Expand description
Encryption key manager.
Holds the derived AES-256 key in memory for the session duration. The key is derived from the user’s passphrase using Argon2id.
Implementations§
Source§impl Encryptor
impl Encryptor
Sourcepub fn from_passphrase(
passphrase: &str,
salt: &[u8],
) -> Result<Self, EncryptionError>
pub fn from_passphrase( passphrase: &str, salt: &[u8], ) -> Result<Self, EncryptionError>
Derive an encryption key from a passphrase and salt.
Uses Argon2id with default parameters (memory=19 MiB, iterations=2, parallelism=1).
Sourcepub fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>, EncryptionError>
pub fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>, EncryptionError>
Encrypt plaintext. Returns nonce || ciphertext.
Each call generates a fresh 96-bit random nonce, prepended to output.
Sourcepub fn decrypt(&self, data: &[u8]) -> Result<Vec<u8>, EncryptionError>
pub fn decrypt(&self, data: &[u8]) -> Result<Vec<u8>, EncryptionError>
Decrypt data produced by encrypt(). Input format: nonce || ciphertext.
Sourcepub fn encrypt_string(&self, plaintext: &str) -> Result<String, EncryptionError>
pub fn encrypt_string(&self, plaintext: &str) -> Result<String, EncryptionError>
Encrypt a string, returning base64-encoded ciphertext.
Sourcepub fn decrypt_string(&self, encoded: &str) -> Result<String, EncryptionError>
pub fn decrypt_string(&self, encoded: &str) -> Result<String, EncryptionError>
Decrypt a base64-encoded ciphertext back to a string.
Sourcepub fn generate_salt() -> [u8; 16]
pub fn generate_salt() -> [u8; 16]
Generate a random salt for key derivation.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Encryptor
impl RefUnwindSafe for Encryptor
impl Send for Encryptor
impl Sync for Encryptor
impl Unpin for Encryptor
impl UnsafeUnpin for Encryptor
impl UnwindSafe for Encryptor
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
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>
Converts
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>
Converts
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