pub trait ProtectedStorage: Send + Sync {
// Required methods
fn prepare(&self, namespace: &str) -> StoreResult<()>;
fn lock(&self, namespace: &str) -> StoreResult<ProtectedStorageLock>;
fn load_secret(
&self,
namespace: &str,
item: &str,
expected_len: usize,
) -> StoreResult<Option<Zeroizing<Vec<u8>>>>;
fn create_secret(
&self,
namespace: &str,
item: &str,
bytes: &[u8],
) -> StoreResult<()>;
fn delete_secret(&self, namespace: &str, item: &str) -> StoreResult<()>;
fn read_record(
&self,
namespace: &str,
name: &str,
expected_len: usize,
) -> StoreResult<Option<Vec<u8>>>;
fn create_record(
&self,
namespace: &str,
name: &str,
bytes: &[u8],
) -> StoreResult<()>;
fn remove_record(&self, namespace: &str, name: &str) -> StoreResult<()>;
fn list_secrets(&self, namespace: &str) -> StoreResult<HashSet<String>>;
fn list_records(&self, namespace: &str) -> StoreResult<HashSet<String>>;
// Provided method
fn database_location(&self, database_path: &Path) -> StoreResult<Vec<u8>> { ... }
}Expand description
Host-owned storage for protected local keys.
Every call names a namespace: a lowercase hex digest of the database’s
location and random client_id, so each database has its own items.
Secret items hold key material and must stay out of database exports,
backups and synchronizing credential stores. Records are nonsecret
markers and public evidence. Both are opaque byte strings.
Creating an item or record never replaces an existing one. Absence is
Ok(None), never an error. Failures map to the stable error classes:
Unavailable while storage can’t be reached (for example, locked),
Corrupt for unsafe or malformed contents and WriteFailed when a write
or delete fails. Messages never contain key material or paths.
Required Methods§
Sourcefn prepare(&self, namespace: &str) -> StoreResult<()>
fn prepare(&self, namespace: &str) -> StoreResult<()>
Makes the namespace ready before first use.
Sourcefn lock(&self, namespace: &str) -> StoreResult<ProtectedStorageLock>
fn lock(&self, namespace: &str) -> StoreResult<ProtectedStorageLock>
Excludes every other process and store using this namespace until the returned lock is dropped.
Sourcefn load_secret(
&self,
namespace: &str,
item: &str,
expected_len: usize,
) -> StoreResult<Option<Zeroizing<Vec<u8>>>>
fn load_secret( &self, namespace: &str, item: &str, expected_len: usize, ) -> StoreResult<Option<Zeroizing<Vec<u8>>>>
The secret item, which callers expect to be expected_len bytes.
Sourcefn create_secret(
&self,
namespace: &str,
item: &str,
bytes: &[u8],
) -> StoreResult<()>
fn create_secret( &self, namespace: &str, item: &str, bytes: &[u8], ) -> StoreResult<()>
Durably saves a secret item that the caller observed absent.
Sourcefn delete_secret(&self, namespace: &str, item: &str) -> StoreResult<()>
fn delete_secret(&self, namespace: &str, item: &str) -> StoreResult<()>
Deletes a secret item; an absent item is already deleted.
Sourcefn read_record(
&self,
namespace: &str,
name: &str,
expected_len: usize,
) -> StoreResult<Option<Vec<u8>>>
fn read_record( &self, namespace: &str, name: &str, expected_len: usize, ) -> StoreResult<Option<Vec<u8>>>
The record, which callers expect to be expected_len bytes.
Sourcefn create_record(
&self,
namespace: &str,
name: &str,
bytes: &[u8],
) -> StoreResult<()>
fn create_record( &self, namespace: &str, name: &str, bytes: &[u8], ) -> StoreResult<()>
Durably saves a new record; an existing record is a failure.
Sourcefn remove_record(&self, namespace: &str, name: &str) -> StoreResult<()>
fn remove_record(&self, namespace: &str, name: &str) -> StoreResult<()>
Removes a record; an absent record is already removed.
Sourcefn list_secrets(&self, namespace: &str) -> StoreResult<HashSet<String>>
fn list_secrets(&self, namespace: &str) -> StoreResult<HashSet<String>>
Names of every secret item in the namespace. Extra names are allowed and only cost a load; a missing name makes its item read as absent. Called under the namespace lock, once per lock.
Sourcefn list_records(&self, namespace: &str) -> StoreResult<HashSet<String>>
fn list_records(&self, namespace: &str) -> StoreResult<HashSet<String>>
Names of every record in the namespace, with the same contract as
Self::list_secrets.
Provided Methods§
Sourcefn database_location(&self, database_path: &Path) -> StoreResult<Vec<u8>>
fn database_location(&self, database_path: &Path) -> StoreResult<Vec<u8>>
Stable bytes naming where the database lives. With its client_id
they name the namespace, so they must not change while the database
stays in place. The default is the canonical path, which suits hosts
whose paths are stable across launches and updates.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".