Skip to main content

revault_vault_api/
content_key_store.rs

1use revault_lockbox_api::{LockboxId, Result, SecretVec};
2use std::path::Path;
3
4/// Storage backend for opened Lockbox content keys.
5///
6/// `Vault` uses this trait to cache content keys after a lockbox is created or
7/// opened, and to retrieve them for later cache-only opens. Implementations
8/// may keep keys in memory, forward them to a local agent, or deliberately
9/// discard them.
10pub trait ContentKeyStore {
11    /// Returns the cached content key for `lockbox_id`, if one is available.
12    fn get_content_key(&self, lockbox_id: LockboxId) -> Result<Option<SecretVec>>;
13
14    /// Stores the opened content key for `lockbox_id`.
15    fn put_content_key(&self, lockbox_id: LockboxId, key: SecretVec) -> Result<()>;
16
17    /// Stores the opened content key with a display path for diagnostics.
18    fn put_content_key_for_path(
19        &self,
20        lockbox_id: LockboxId,
21        key: SecretVec,
22        _path: &Path,
23    ) -> Result<()> {
24        self.put_content_key(lockbox_id, key)
25    }
26
27    /// Stores the opened content key with an explicit cache lifetime.
28    fn put_content_key_for_path_with_ttl(
29        &self,
30        lockbox_id: LockboxId,
31        key: SecretVec,
32        path: &Path,
33        _ttl_seconds: u64,
34    ) -> Result<()> {
35        self.put_content_key_for_path(lockbox_id, key, path)
36    }
37
38    /// Removes the cached content key for `lockbox_id`.
39    fn forget_content_key(&self, lockbox_id: LockboxId) -> Result<()>;
40
41    /// Removes all cached content keys known to this store.
42    fn forget_all_content_keys(&self) -> Result<()>;
43}