Skip to main content

EncryptionContext

Struct EncryptionContext 

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

Runtime context for encryption operations.

This is the active encryption state for a connected client, including resolved CEKs and encryptors.

The context holds an Arc<EncryptionConfig> so providers remain accessible across connection retries/redirects where the Config (and its inner encryption config Arc) gets cloned multiple times.

Implementations§

Source§

impl EncryptionContext

Source

pub fn from_arc(config: Arc<EncryptionConfig>) -> Self

Create a new encryption context from an Arc-wrapped configuration.

The Arc is retained by the context so provider lookups continue to work for the lifetime of the client — regardless of how many times the outer Config has been cloned for retry/redirect handling.

Source

pub fn new(config: EncryptionConfig) -> Self

Create a new encryption context from configuration.

Source

pub async fn get_encryptor( &self, cek_entry: &CekTableEntry, ) -> Result<Arc<AeadEncryptor>, EncryptionError>

Get or decrypt a CEK for a column.

This handles the CEK caching and decryption logic:

  1. Check cache for existing encryptor
  2. If not cached, decrypt CEK using the appropriate key store
  3. Create and cache the encryptor
Source

pub async fn encrypt_value( &self, plaintext: &[u8], cek_entry: &CekTableEntry, encryption_type: EncryptionTypeWire, ) -> Result<Vec<u8>, EncryptionError>

Encrypt a value for a column.

§Arguments
  • plaintext - The plaintext value to encrypt
  • cek_entry - The CEK table entry for this column
  • encryption_type - Deterministic or randomized encryption
Source

pub async fn decrypt_value( &self, ciphertext: &[u8], cek_entry: &CekTableEntry, ) -> Result<Vec<u8>, EncryptionError>

Decrypt a value from an encrypted column.

§Arguments
  • ciphertext - The encrypted value
  • cek_entry - The CEK table entry for this column
Source

pub fn clear_cache(&self)

Clear the CEK cache.

Call this when keys may have been rotated.

Source

pub fn has_provider(&self, name: &str) -> bool

Check if a provider is registered.

Trait Implementations§

Source§

impl Debug for EncryptionContext

Available on crate feature always-encrypted only.
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more