pub trait Storage: Send + Sync {
// Required methods
fn store(
&self,
key: &str,
data: &[u8],
) -> impl Future<Output = Result<(), PlatformError>> + Send;
fn retrieve(
&self,
key: &str,
) -> impl Future<Output = Result<Option<Vec<u8>>, PlatformError>> + Send;
fn delete(
&self,
key: &str,
) -> impl Future<Output = Result<(), PlatformError>> + Send;
fn list_keys(
&self,
prefix: &str,
) -> impl Future<Output = Result<Vec<String>, PlatformError>> + Send;
fn delete_prefix(
&self,
prefix: &str,
) -> impl Future<Output = Result<u64, PlatformError>> + Send;
fn exists(
&self,
key: &str,
) -> impl Future<Output = Result<bool, PlatformError>> + Send;
}Expand description
Persistent key-value byte storage trait.
Abstracts platform-specific secure storage (Keychain, encrypted SQLite,
browser IndexedDB). Keys are UTF-8 strings; values are opaque byte
slices. The testing implementation stores data in an in-memory HashMap.
See ADR-006.
Required Methods§
Sourcefn store(
&self,
key: &str,
data: &[u8],
) -> impl Future<Output = Result<(), PlatformError>> + Send
fn store( &self, key: &str, data: &[u8], ) -> impl Future<Output = Result<(), PlatformError>> + Send
Store a byte slice under the given key.
Overwrites any existing value for the same key.
§Errors
Returns PlatformError::StorageError if the write fails.
Sourcefn retrieve(
&self,
key: &str,
) -> impl Future<Output = Result<Option<Vec<u8>>, PlatformError>> + Send
fn retrieve( &self, key: &str, ) -> impl Future<Output = Result<Option<Vec<u8>>, PlatformError>> + Send
Retrieve the byte slice stored under the given key.
Returns None if the key does not exist.
§Errors
Returns PlatformError::StorageError if the read fails.
Sourcefn delete(
&self,
key: &str,
) -> impl Future<Output = Result<(), PlatformError>> + Send
fn delete( &self, key: &str, ) -> impl Future<Output = Result<(), PlatformError>> + Send
Delete the value stored under the given key.
No-op if the key does not exist.
§Errors
Returns PlatformError::StorageError if the delete fails.
Sourcefn list_keys(
&self,
prefix: &str,
) -> impl Future<Output = Result<Vec<String>, PlatformError>> + Send
fn list_keys( &self, prefix: &str, ) -> impl Future<Output = Result<Vec<String>, PlatformError>> + Send
List all keys matching the given prefix in lexicographic order.
Useful for KeyPackage buffer management and event log range queries.
§Errors
Returns PlatformError::StorageError if the operation fails.
Sourcefn delete_prefix(
&self,
prefix: &str,
) -> impl Future<Output = Result<u64, PlatformError>> + Send
fn delete_prefix( &self, prefix: &str, ) -> impl Future<Output = Result<u64, PlatformError>> + Send
Delete all keys matching the given prefix.
Returns the number of keys deleted. Used for context cleanup. See
ADR-006 acceptance criterion 4 (InMemoryStorage).
§Errors
Returns PlatformError::StorageError if the operation fails.
Sourcefn exists(
&self,
key: &str,
) -> impl Future<Output = Result<bool, PlatformError>> + Send
fn exists( &self, key: &str, ) -> impl Future<Output = Result<bool, PlatformError>> + Send
Check whether a key exists without reading its value.
Used for UCAN nonce replay prevention. See ADR-006 acceptance
criterion 4 (InMemoryStorage).
§Errors
Returns PlatformError::StorageError if the operation fails.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<T: Storage> Storage for Arc<T>
Blanket implementation of Storage for Arc<T> where T: Storage.
impl<T: Storage> Storage for Arc<T>
Blanket implementation of Storage for Arc<T> where T: Storage.
Enables sharing a single storage backend across multiple owners (e.g.,
ProtocolStore, identity layer, and FFI bridge) via Arc. Delegates all
operations to the inner T via Deref.
This is essential for ProtocolStore<Arc<S>> to work when the storage
backend is shared via Arc (e.g., the FFI bridge’s global
STORAGE_PROVIDER). See issue #329.