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