FileStore

Struct FileStore 

Source
pub struct FileStore { /* private fields */ }
Expand description

File-based key store with optional encryption

Provides persistent storage of cryptographic keys with optional encryption at rest The key are cached in memory for performance and automatically loaded from disk

Implementations§

Source§

impl FileStore

Source

pub fn new<P: AsRef<Path>>(path: P, config: StorageConfig) -> Result<Self>

Create a new FileStore at the given path

Source

pub fn rekey(&mut self, new_password: &[u8]) -> Result<()>

Source

pub fn set_master_key(&mut self, key: SecretKey) -> Result<()>

Set master key for encryption

Source

pub fn init_with_password(&mut self, password: &[u8]) -> Result<()>

Initialize with password-derived master key (now using per-vault salt)

Source

pub fn derive_master_key( password: &[u8], salt: &[u8], argon2_config: &Argon2Config, ) -> Result<SecretKey>

Derive a master key from a password using Argon2id

Source

pub fn enable_audit_log<P: AsRef<Path>>(&mut self, log_path: P) -> Result<()>

Enable audit logging to a file

Source

pub fn set_audit_logger(&mut self, logger: Box<dyn AuditLogger>)

Set a custom audit logger

Source

pub fn export_key(&mut self, id: &KeyId, password: &[u8]) -> Result<ExportedKey>

Export a key to a secure, portable format

The key is encrypted with a password-derived key using Argon2id. The exported key includes all metadata and can be imported into another vault.

Source

pub fn import_key( &mut self, exported: &ExportedKey, password: &[u8], ) -> Result<KeyId>

Import a key from an exported format

Validates the key, decrypts it with the provided password, and stores it in the vault. The key will maintain its original metadata (algorithm, version, etc.).

Source

pub fn backup( &mut self, password: &[u8], config: BackupConfig, ) -> Result<VaultBackup>

Create a full backup of the vault

§Arguments
  • password - Password to encrypt the backup
  • config - Backup configuration
§Returns

The encrypted backup that can be saved to a file

§Security

The backup is encrypted using Argon2id key derivation and XChaCha20Poly1305 AEAD. All key material is protected with high-security parameters.

Source

pub fn restore( &mut self, backup: &VaultBackup, password: &[u8], ) -> Result<usize>

Restore a vault from a backup

§Arguments
  • backup - The encrypted backup to restore
  • password - Password used to encrypt the backup
§Errors

Returns an error if:

  • Password is incorrect
  • Backup is corrupted
  • Keys cannot be imported

Trait Implementations§

Source§

impl Debug for FileStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl KeyLifeCycle for FileStore

Source§

fn deprecate_key(&mut self, id: &KeyId) -> Result<()>

Mark a particular key as deprecated (key should be able to decrypt but not encrypt)
Source§

fn revoke_key(&mut self, id: &KeyId) -> Result<()>

Revoke a key (key should not be used for any operations)
Source§

fn cleanup_old_versions( &mut self, id: &KeyId, keep_versions: usize, ) -> Result<Vec<KeyId>>

Clean up old versions based on policy
Source§

impl KeyStore for FileStore

Source§

fn store(&mut self, key: VersionedKey) -> Result<()>

Store a versioned key
Source§

fn retrieve(&self, id: &KeyId) -> Result<VersionedKey>

Retrieve a key by ID
Source§

fn delete(&mut self, id: &KeyId) -> Result<()>

Delete a key
Source§

fn list(&self) -> Result<Vec<KeyId>>

List all kety IDs
Source§

fn update_metadata(&mut self, id: &KeyId, metadata: KeyMetadata) -> Result<()>

Update key metadata
Source§

fn find_by_state(&self, state: KeyState) -> Result<Vec<KeyId>>

Find keys by state
Source§

fn rotate_key(&mut self, id: &KeyId) -> Result<VersionedKey>

Rotate a key to a new version
Source§

fn get_key_versions(&self, id: &KeyId) -> Result<Vec<VersionedKey>>

Get all verions of a key (sorted by version number)
Source§

fn get_latest_key(&self, id: &KeyId) -> Result<VersionedKey>

Get the latest active version of a key
Source§

impl PersistentStorage for FileStore

Source§

fn flush(&mut self) -> Result<()>

Flush any pending writes to persistent storage
Source§

fn load(&mut self) -> Result<()>

Load keys from persistent storage
Source§

fn location(&self) -> &str

Get the storage location/path

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V