pub struct DatabaseFieldAdapter { /* private fields */ }Expand description
Basic implementation of EncryptedFieldAdapter
Uses SecretsManager to fetch encryption keys from Vault and caches ciphers for performance.
Implementations§
Source§impl DatabaseFieldAdapter
impl DatabaseFieldAdapter
Sourcepub fn new(
secrets_manager: Arc<SecretsManager>,
field_keys: HashMap<String, String>,
) -> Self
pub fn new( secrets_manager: Arc<SecretsManager>, field_keys: HashMap<String, String>, ) -> Self
Create new database field adapter
§Arguments
secrets_manager- SecretsManager for fetching encryption keys from Vaultfield_keys- Mapping of database field names to Vault key names
§Example
ⓘ
let mut field_keys = HashMap::new();
field_keys.insert("email".to_string(), "db/email_key".to_string());
field_keys.insert("phone".to_string(), "db/phone_key".to_string());
let adapter = DatabaseFieldAdapter::new(secrets_manager, field_keys);Sourcepub fn register_field(
&mut self,
field_name: impl Into<String>,
key_name: impl Into<String>,
)
pub fn register_field( &mut self, field_name: impl Into<String>, key_name: impl Into<String>, )
Register new encrypted field with its encryption key
§Arguments
field_name- Database field name to be encryptedkey_name- Vault secret name for the encryption key
Sourcepub async fn invalidate_cache(&self)
pub async fn invalidate_cache(&self)
Invalidate cipher cache, forcing fresh key retrieval from SecretsManager
Useful after key rotation in Vault. Next encryption/decryption will fetch the new key and create a new cipher.
Sourcepub async fn invalidate_field_cache(&self, field_name: &str)
pub async fn invalidate_field_cache(&self, field_name: &str)
Sourcepub async fn cache_size(&self) -> usize
pub async fn cache_size(&self) -> usize
Get current cache size
Returns number of cached ciphers (one per encrypted field being used).
Trait Implementations§
Source§impl EncryptedFieldAdapter for DatabaseFieldAdapter
impl EncryptedFieldAdapter for DatabaseFieldAdapter
Source§fn get_encrypted_fields(&self) -> Vec<String>
fn get_encrypted_fields(&self) -> Vec<String>
Get list of encrypted field names
Source§async fn encrypt_value(
&self,
field_name: &str,
plaintext: &str,
) -> Result<Vec<u8>, SecretsError>
async fn encrypt_value( &self, field_name: &str, plaintext: &str, ) -> Result<Vec<u8>, SecretsError>
Encrypt a plaintext value for the given field
Source§async fn decrypt_value(
&self,
field_name: &str,
ciphertext: &[u8],
) -> Result<String, SecretsError>
async fn decrypt_value( &self, field_name: &str, ciphertext: &[u8], ) -> Result<String, SecretsError>
Decrypt an encrypted value for the given field
Source§async fn encrypt_with_context(
&self,
field_name: &str,
plaintext: &str,
context: &str,
) -> Result<Vec<u8>, SecretsError>
async fn encrypt_with_context( &self, field_name: &str, plaintext: &str, context: &str, ) -> Result<Vec<u8>, SecretsError>
Encrypt with additional context for audit trail
Source§async fn decrypt_with_context(
&self,
field_name: &str,
ciphertext: &[u8],
context: &str,
) -> Result<String, SecretsError>
async fn decrypt_with_context( &self, field_name: &str, ciphertext: &[u8], context: &str, ) -> Result<String, SecretsError>
Decrypt with context verification
Source§fn is_encrypted(&self, field_name: &str) -> bool
fn is_encrypted(&self, field_name: &str) -> bool
Check if a field is encrypted
Auto Trait Implementations§
impl Freeze for DatabaseFieldAdapter
impl !RefUnwindSafe for DatabaseFieldAdapter
impl Send for DatabaseFieldAdapter
impl Sync for DatabaseFieldAdapter
impl Unpin for DatabaseFieldAdapter
impl !UnwindSafe for DatabaseFieldAdapter
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> 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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request