Skip to main content

SecureCache

Struct SecureCache 

Source
pub struct SecureCache<'a> { /* private fields */ }
Expand description

Encrypted cache handle returned by CacheKit::secure_cache().

All values are serialized, then encrypted with AES-256-GCM before storage. L1 stores ciphertext to maintain zero-knowledge guarantees. The client’s own value methods route through these same methods once encryption is configured, so the handle and the client read each other’s entries.

The handle borrows its CacheKit (SecureCache<'a> holds &'a CacheKit), so it cannot be stored in the same struct as the client it came from. Store the CacheKit and call CacheKit::secure_cache() where you need the handle: it only checks that encryption is configured and copies two references, so calling it per operation is cheap.

Implementations§

Source§

impl SecureCache<'_>

Source

pub fn previous_key_hits(&self) -> Vec<u64>

Rotation drain signal; see EncryptionLayer::previous_key_hits.

Source

pub fn hardware_acceleration_enabled(&self) -> bool

Whether AES is hardware-accelerated on this host (informational); see EncryptionLayer::hardware_acceleration_enabled.

Source

pub async fn set<T: Serialize>( &self, key: &str, value: &T, ) -> Result<(), CachekitError>

Encrypt and store value under key using the client’s default TTL.

Source

pub async fn set_with_ttl<T: Serialize>( &self, key: &str, value: &T, ttl: Duration, ) -> Result<(), CachekitError>

Encrypt and store value under key with an explicit ttl.

A positive sub-second ttl is sent to the backend as 1 second.

Returns CachekitError::Config if ttl is zero.

The client namespace is not checked here: an interop key written on a namespaced client lands under {namespace}:{interop_key}, which no interop reader addresses — see CacheKit::interop_get.

Source

pub async fn get<T: DeserializeOwned>( &self, key: &str, ) -> Result<Option<T>, CachekitError>

Retrieve, decrypt, and deserialize a value stored under key.

Checks L1 (which holds ciphertext) before the backend.

§Errors

Returns CachekitError::Encryption if the stored entry fails decryption. The key’s L1 copy is dropped first and the backend entry is left in place, so the next read reaches the backend: a hit once the entry is replaced with ciphertext this client can decrypt, a miss once it expires or is deleted. A decrypted entry that does not decode as T is CachekitError::Serialization naming only T: the decoder’s own message would quote the plaintext.

Source

pub async fn interop_get<T: DeserializeOwned>( &self, key: &str, ) -> Result<Option<T>, CachekitError>

Retrieve, decrypt, and deserialize an interop-mode value stored under key.

Identical to Self::get except the decrypted plaintext is decoded with crate::interop::deserialize — exactly one MessagePack document, trailing bytes rejected (interop/v1 spec MUST), as in Self::get. In interop mode the AES-GCM plaintext is the plain MessagePack value bytes, so the AAD (v0x03, format="msgpack", compressed="False") verifies cross-SDK unchanged.

§Errors

Returns CachekitError::Config on a namespace-prefixed client — see CacheKit::interop_get — and CachekitError::Encryption if the stored entry fails decryption, with the key’s L1 copy dropped as for Self::get.

Source

pub async fn interop_get_swr<T: DeserializeOwned>( &self, key: &str, ) -> Result<SwrRead<T>, CachekitError>

Retrieve, decrypt, and deserialize an interop-mode value with SWR classification. The secure twin of CacheKit::interop_get_swr: staleness is judged on the L1 ciphertext entry (zero-knowledge is preserved — freshness metadata never exposes plaintext), then the value is decrypted and decoded per Self::interop_get.

§Errors

Same as Self::interop_get — the secure path fails closed on every backend and decryption error.

Source

pub async fn delete(&self, key: &str) -> Result<bool, CachekitError>

Delete an encrypted key. Behaves identically to CacheKit::delete.

Source

pub async fn exists(&self, key: &str) -> Result<bool, CachekitError>

Check if an encrypted key exists. Behaves identically to CacheKit::exists.

Trait Implementations§

Source§

impl Debug for SecureCache<'_>

Available on crate feature encryption only.
Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for SecureCache<'a>

§

impl<'a> !UnwindSafe for SecureCache<'a>

§

impl<'a> Freeze for SecureCache<'a>

§

impl<'a> Send for SecureCache<'a>

§

impl<'a> Sync for SecureCache<'a>

§

impl<'a> Unpin for SecureCache<'a>

§

impl<'a> UnsafeUnpin for SecureCache<'a>

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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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 more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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