pub struct FieldEncryption { /* private fields */ }Expand description
Main encryption service for field-level encryption
Implementations§
Source§impl FieldEncryption
impl FieldEncryption
Sourcepub fn new() -> Result<Self, EncryptionError>
pub fn new() -> Result<Self, EncryptionError>
Creates a new FieldEncryption instance using a key from environment variables
§Environment Variables
STORAGE_ENCRYPTION_KEY: Base64-encoded 32-byte encryption key
Sourcepub fn new_with_key(key: &[u8; 32]) -> Result<Self, EncryptionError>
pub fn new_with_key(key: &[u8; 32]) -> Result<Self, EncryptionError>
Creates a new FieldEncryption instance with a provided key (for testing)
Sourcepub fn encrypt(
&self,
plaintext: &[u8],
) -> Result<EncryptedData, EncryptionError>
pub fn encrypt( &self, plaintext: &[u8], ) -> Result<EncryptedData, EncryptionError>
Encrypts plaintext data and returns an EncryptedData structure
Sourcepub fn decrypt(
&self,
encrypted_data: &EncryptedData,
) -> Result<Vec<u8>, EncryptionError>
pub fn decrypt( &self, encrypted_data: &EncryptedData, ) -> Result<Vec<u8>, EncryptionError>
Decrypts an EncryptedData structure and returns the plaintext (v1, no AAD)
Sourcepub fn encrypt_with_aad(
&self,
plaintext: &[u8],
aad: &[u8],
) -> Result<EncryptedData, EncryptionError>
pub fn encrypt_with_aad( &self, plaintext: &[u8], aad: &[u8], ) -> Result<EncryptedData, EncryptionError>
Encrypts plaintext data with AAD and returns an EncryptedData structure (version 2)
AAD (Additional Authenticated Data) binds the ciphertext to a specific context, preventing ciphertext swap attacks where encrypted data could be moved between different storage locations.
Sourcepub fn decrypt_with_aad(
&self,
encrypted_data: &EncryptedData,
aad: &[u8],
) -> Result<Vec<u8>, EncryptionError>
pub fn decrypt_with_aad( &self, encrypted_data: &EncryptedData, aad: &[u8], ) -> Result<Vec<u8>, EncryptionError>
Decrypts an EncryptedData structure with AAD and returns the plaintext (version 2)
The AAD must match what was used during encryption, otherwise decryption will fail. This prevents ciphertext swap attacks.
Sourcepub fn decrypt_auto(
&self,
encrypted_data: &EncryptedData,
aad: Option<&[u8]>,
) -> Result<Vec<u8>, EncryptionError>
pub fn decrypt_auto( &self, encrypted_data: &EncryptedData, aad: Option<&[u8]>, ) -> Result<Vec<u8>, EncryptionError>
Auto-detect version and decrypt accordingly
- Version 1: Decrypts without AAD (legacy)
- Version 2: Decrypts with AAD (requires aad parameter)
This enables backwards compatibility with existing v1 encrypted data while supporting the new v2 format with AAD.
Sourcepub fn encrypt_string(&self, plaintext: &str) -> Result<String, EncryptionError>
pub fn encrypt_string(&self, plaintext: &str) -> Result<String, EncryptionError>
Encrypts a string and returns base64-encoded encrypted data (opaque format)
Sourcepub fn decrypt_string(
&self,
encrypted_base64: &str,
) -> Result<String, EncryptionError>
pub fn decrypt_string( &self, encrypted_base64: &str, ) -> Result<String, EncryptionError>
Decrypts a base64-encoded encrypted string
Sourcepub fn generate_key() -> String
pub fn generate_key() -> String
Utility function to generate a new encryption key for setup
Sourcepub fn is_configured() -> bool
pub fn is_configured() -> bool
Checks if encryption is properly configured
Trait Implementations§
Source§impl Clone for FieldEncryption
impl Clone for FieldEncryption
Source§fn clone(&self) -> FieldEncryption
fn clone(&self) -> FieldEncryption
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for FieldEncryption
impl RefUnwindSafe for FieldEncryption
impl Send for FieldEncryption
impl Sync for FieldEncryption
impl Unpin for FieldEncryption
impl UnwindSafe for FieldEncryption
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more