Skip to main content

KeyStore

Trait KeyStore 

Source
pub trait KeyStore: Send + Sync {
    // Required methods
    fn store_key<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
        material: &'life2 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<(), KeyStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn load_key<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, KeyStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn delete_key<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), KeyStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn key_exists<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<bool, KeyStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn list_keys<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, KeyStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for key storage backends

Implement this trait to integrate with external key management systems. All operations are async to support network-based backends (HSMs, cloud KMS, etc.).

§Thread Safety

Implementations must be Send + Sync to allow use across async tasks.

§Error Handling

Implementations should:

  • Return KeyStoreError::NotFound for missing keys (not a general error)
  • Return KeyStoreError::AccessDenied for permission issues
  • Return KeyStoreError::Unavailable for transient failures (enable retry logic)
  • Return KeyStoreError::Storage for other backend errors

Required Methods§

Source

fn store_key<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 str, material: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), KeyStoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Store key material with the given identifier

If a key with the same ID already exists, it should be overwritten.

§Arguments
  • id - Unique identifier for the key (typically a DID or key ID)
  • material - Raw key material (private key bytes)
Source

fn load_key<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, KeyStoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load key material by identifier

§Arguments
  • id - The key identifier
§Returns

The raw key material, or KeyStoreError::NotFound if the key doesn’t exist

Source

fn delete_key<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), KeyStoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a key by identifier

§Arguments
  • id - The key identifier
§Returns

Ok(()) if the key was deleted or didn’t exist

Source

fn key_exists<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool, KeyStoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Check if a key exists

§Arguments
  • id - The key identifier
§Returns

true if the key exists, false otherwise

Source

fn list_keys<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, KeyStoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all key identifiers

§Returns

A vector of all key IDs in the store

Implementors§