Skip to main content

ProductKeyCache

Struct ProductKeyCache 

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

In-memory cache mapping (product_id, index)pubkey.

The cache is bound to a single phone identity at construction time. Callers must pass the current phone identity on every read and write so the cache can detect re-pairing events and self-invalidate automatically.

Implementations§

Source§

impl ProductKeyCache

Source

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

Create an empty cache bound to phone_identity.

Source

pub fn identity(&self) -> &[u8; 32]

Return the phone identity this cache is bound to.

Source

pub fn get( &mut self, phone_identity: &[u8; 32], product_id: &str, index: u32, ) -> Option<[u8; 32]>

Look up a cached key for (product_id, index).

Returns None on a cache miss. If phone_identity differs from the stored identity the entire cache is cleared and None is returned — this handles re-pairing with a different phone transparently.

Source

pub fn insert( &mut self, phone_identity: &[u8; 32], product_id: &str, index: u32, pubkey: [u8; 32], ) -> Result<(), CacheIdentityMismatch>

Store a key for (product_id, index).

Returns Err(CacheIdentityMismatch) if phone_identity differs from the stored identity; callers should log this as a security event and consider clearing the cache before retrying.

Source

pub fn remove(&mut self, product_id: &str, index: u32)

Remove a single entry. No-op if the entry does not exist.

Source

pub fn clear(&mut self)

Clear all cached entries. The bound identity is preserved.

Source

pub fn to_entries(&self) -> Vec<ProductKeyCacheEntry>

Snapshot all entries for persistence.

Source

pub fn load_from( &mut self, identity: &[u8; 32], entries: &[ProductKeyCacheEntry], )

Populate the cache from a previously persisted snapshot.

If identity does not match the cache’s bound identity the snapshot is silently ignored — it belongs to a different pairing session.

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, 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, 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