pub trait KeyStore: Send + Sync {
// Required methods
fn store(
&self,
name: &str,
key: &SecretKey,
passphrase: &str,
) -> Result<(), StoreError>;
fn load(
&self,
name: &str,
passphrase: &str,
) -> Result<SecretKey, StoreError>;
fn list(&self) -> Result<Vec<String>, StoreError>;
fn delete(&self, name: &str) -> Result<(), StoreError>;
fn exists(&self, name: &str) -> bool;
}Expand description
Trait for secure key storage.
Implementations must ensure:
- Keys are encrypted at rest
- File permissions prevent unauthorized access
- Atomic operations prevent corruption
- Thread-safe operations (
Send + Sync)
§Example
use txgate_crypto::store::{KeyStore, FileKeyStore};
use txgate_crypto::keys::SecretKey;
fn example<S: KeyStore>(store: &S) -> Result<(), txgate_core::error::StoreError> {
let key = SecretKey::generate();
store.store("my-key", &key, "passphrase")?;
if store.exists("my-key") {
let loaded = store.load("my-key", "passphrase")?;
}
Ok(())
}Required Methods§
Sourcefn store(
&self,
name: &str,
key: &SecretKey,
passphrase: &str,
) -> Result<(), StoreError>
fn store( &self, name: &str, key: &SecretKey, passphrase: &str, ) -> Result<(), StoreError>
Store a secret key with the given name.
§Arguments
name- A unique identifier for the key (e.g., “default”, “hot-wallet”)key- The secret key to storepassphrase- The passphrase to encrypt the key with
§Errors
StoreError::KeyExistsif a key with this name already existsStoreError::EncryptionFailedif encryption failsStoreError::IoErrorif file operations failStoreError::InvalidFormatif the name is invalid
Sourcefn load(&self, name: &str, passphrase: &str) -> Result<SecretKey, StoreError>
fn load(&self, name: &str, passphrase: &str) -> Result<SecretKey, StoreError>
Load a secret key by name.
§Arguments
name- The identifier of the key to loadpassphrase- The passphrase to decrypt the key with
§Errors
StoreError::KeyNotFoundif no key exists with this nameStoreError::DecryptionFailedif the passphrase is wrongStoreError::IoErrorif file operations failStoreError::InvalidFormatif the name or file format is invalid