pub trait EncryptedFieldAdapter: Send + Sync {
// Required methods
fn get_encrypted_fields(&self) -> Vec<String>;
async fn encrypt_value(
&self,
field_name: &str,
plaintext: &str,
) -> Result<Vec<u8>, SecretsError>;
async fn decrypt_value(
&self,
field_name: &str,
ciphertext: &[u8],
) -> Result<String, SecretsError>;
async fn encrypt_with_context(
&self,
field_name: &str,
plaintext: &str,
context: &str,
) -> Result<Vec<u8>, SecretsError>;
async fn decrypt_with_context(
&self,
field_name: &str,
ciphertext: &[u8],
context: &str,
) -> Result<String, SecretsError>;
// Provided method
fn is_encrypted(&self, field_name: &str) -> bool { ... }
}Expand description
Trait for managing encrypted fields in database adapters
Enables automatic encryption/decryption at the query layer without requiring manual encryption/decryption in application code.
Required Methods§
Sourcefn get_encrypted_fields(&self) -> Vec<String>
fn get_encrypted_fields(&self) -> Vec<String>
Get list of encrypted field names
Sourceasync 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
Sourceasync 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
Sourceasync 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
Sourceasync 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
Provided Methods§
Sourcefn is_encrypted(&self, field_name: &str) -> bool
fn is_encrypted(&self, field_name: &str) -> bool
Check if a field is encrypted
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.