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
impl FileKeyStore
Sourcepub fn new() -> Result<Self, StoreError>
pub fn new() -> Result<Self, StoreError>
Create a new FileKeyStore with the default path (~/.txgate/keys/).
§Errors
StoreError::IoErrorif the home directory cannot be determinedStoreError::IoErrorif directory creation failsStoreError::PermissionDeniedif permissions cannot be set
§Example
use txgate_crypto::store::FileKeyStore;
let store = FileKeyStore::new().expect("failed to create key store");Sourcepub fn with_path(keys_dir: PathBuf) -> Result<Self, StoreError>
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::IoErrorif directory creation failsStoreError::PermissionDeniedif 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");Trait Implementations§
Source§impl KeyStore for FileKeyStore
impl KeyStore for FileKeyStore
Auto Trait Implementations§
impl Freeze for FileKeyStore
impl RefUnwindSafe for FileKeyStore
impl Send for FileKeyStore
impl Sync for FileKeyStore
impl Unpin for FileKeyStore
impl UnwindSafe for FileKeyStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more