Skip to main content

FileKeyStore

Struct FileKeyStore 

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

File-based key storage in ~/.txgate/keys/.

This implementation stores encrypted keys as individual files with the .enc extension. Each key is encrypted using the encryption module’s ChaCha20-Poly1305 AEAD encryption with Argon2id key derivation.

§Security

  • Directory permissions are set to 0700 (owner only)
  • File permissions are set to 0600 (owner read/write only)
  • Atomic writes prevent corruption on crash
  • Key names are validated to prevent path traversal attacks

§Example

use txgate_crypto::store::{KeyStore, FileKeyStore};

// Use the default path (~/.txgate/keys/)
let store = FileKeyStore::new().expect("failed to create key store");

// Or use a custom path
use std::path::PathBuf;
let custom_store = FileKeyStore::with_path(PathBuf::from("/custom/path"))
    .expect("failed to create key store");

Implementations§

Source§

impl FileKeyStore

Source

pub fn new() -> Result<Self, StoreError>

Create a new FileKeyStore with the default path (~/.txgate/keys/).

§Errors
  • StoreError::IoError if the home directory cannot be determined
  • StoreError::IoError if directory creation fails
  • StoreError::PermissionDenied if permissions cannot be set
§Example
use txgate_crypto::store::FileKeyStore;

let store = FileKeyStore::new().expect("failed to create key store");
Source

pub fn with_path(keys_dir: PathBuf) -> Result<Self, StoreError>

Create a FileKeyStore with a custom path.

This is useful for testing or when you want to store keys in a non-standard location.

§Arguments
  • keys_dir - The directory to store keys in
§Errors
  • StoreError::IoError if directory creation fails
  • StoreError::PermissionDenied if permissions cannot be set
§Example
use txgate_crypto::store::FileKeyStore;
use std::path::PathBuf;

let store = FileKeyStore::with_path(PathBuf::from("/tmp/test-keys"))
    .expect("failed to create key store");
Source

pub const fn keys_dir(&self) -> &PathBuf

Get the directory path where keys are stored.

This is useful for debugging or informational purposes.

Trait Implementations§

Source§

impl KeyStore for FileKeyStore

Source§

fn store( &self, name: &str, key: &SecretKey, passphrase: &str, ) -> Result<(), StoreError>

Store a secret key with the given name. Read more
Source§

fn load(&self, name: &str, passphrase: &str) -> Result<SecretKey, StoreError>

Load a secret key by name. Read more
Source§

fn list(&self) -> Result<Vec<String>, StoreError>

List all stored key names. Read more
Source§

fn delete(&self, name: &str) -> Result<(), StoreError>

Delete a key by name. Read more
Source§

fn exists(&self, name: &str) -> bool

Check if a key exists. Read more

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