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
impl ProductKeyCache
Sourcepub fn get(
&mut self,
phone_identity: &[u8; 32],
product_id: &str,
index: u32,
) -> Option<[u8; 32]>
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.
Sourcepub fn insert(
&mut self,
phone_identity: &[u8; 32],
product_id: &str,
index: u32,
pubkey: [u8; 32],
) -> Result<(), CacheIdentityMismatch>
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.
Sourcepub fn remove(&mut self, product_id: &str, index: u32)
pub fn remove(&mut self, product_id: &str, index: u32)
Remove a single entry. No-op if the entry does not exist.
Sourcepub fn to_entries(&self) -> Vec<ProductKeyCacheEntry>
pub fn to_entries(&self) -> Vec<ProductKeyCacheEntry>
Snapshot all entries for persistence.
Sourcepub fn load_from(
&mut self,
identity: &[u8; 32],
entries: &[ProductKeyCacheEntry],
)
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.