Skip to main content

FieldEncryptor

Struct FieldEncryptor 

Source
pub struct FieldEncryptor { /* private fields */ }
Expand description

Field-level encryption using AES-256-GCM.

Each encrypted field has the wire format: base64(key_version_1 || nonce_12_bytes || ciphertext_with_tag)

The 1-byte key version prefix enables future key rotation: the decryptor can identify which key was used and select the correct one.

A fresh random nonce is generated for every encrypt_* call, so encrypting the same plaintext twice yields different ciphertext.

Implementations§

Source§

impl FieldEncryptor

Source

pub fn new(key: &[u8; 32]) -> Self

Create from a raw 32-byte key.

Source

pub fn with_previous_key(self, key: &[u8; 32]) -> Self

Set a previous key for rotation. During decryption, if the current key fails, the previous key is tried. This allows a rolling upgrade window where old data is still readable.

Source

pub fn from_hex_key(hex_key: &str) -> Result<Self, EncryptionError>

Create from a hex-encoded key string (64 hex chars = 32 bytes).

Source

pub fn with_previous_hex_key( self, hex_key: &str, ) -> Result<Self, EncryptionError>

Create from a hex-encoded previous key for rotation support.

Source

pub fn from_env() -> Result<Option<Self>, EncryptionError>

Create from the ARBITER_STORAGE_ENCRYPTION_KEY environment variable.

Returns Ok(None) when the variable is absent or empty (encryption disabled). Returns Err when the variable is present but malformed.

Source

pub fn encrypt_field(&self, plaintext: &str) -> Result<String, EncryptionError>

Encrypt a UTF-8 string field.

Returns a base64-encoded blob containing nonce || ciphertext.

Source

pub fn decrypt_field(&self, encoded: &str) -> Result<String, EncryptionError>

Decrypt a base64-encoded nonce || ciphertext blob back to the original UTF-8 string.

Source

pub fn encrypt_string_vec( &self, values: &[String], ) -> Result<String, EncryptionError>

Encrypt a Vec<String> by JSON-serializing then encrypting.

Source

pub fn decrypt_string_vec( &self, ciphertext: &str, ) -> Result<Vec<String>, EncryptionError>

Decrypt back to Vec<String>.

Trait Implementations§

Source§

impl Clone for FieldEncryptor

Source§

fn clone(&self) -> FieldEncryptor

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V