pub struct CredentialsStore { /* private fields */ }Expand description
Credential storage abstraction.
By default, stores credentials in a JSON file (~/.lore/credentials.json).
Can optionally use the OS keychain (macOS Keychain, GNOME Keyring, Windows
Credential Manager) when enabled via use_keychain config option.
Implementations§
Source§impl CredentialsStore
impl CredentialsStore
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new credential store with file-based storage (default).
Credentials are stored in ~/.lore/credentials.json with restricted permissions.
Sourcepub fn with_keychain(use_keychain: bool) -> Self
pub fn with_keychain(use_keychain: bool) -> Self
Creates a credential store with optional keychain support.
If use_keychain is true and the OS keychain is available, credentials
will be stored in the keychain. Otherwise, falls back to file storage.
Note: On first keychain access, the OS may prompt for permission.
Sourcepub fn is_keyring_available() -> bool
pub fn is_keyring_available() -> bool
Tests whether the keyring is available by attempting a dummy operation.
This is useful for checking if the OS keychain can be used before prompting the user about credential storage options.
Sourcepub fn is_secret_service_available() -> bool
pub fn is_secret_service_available() -> bool
Checks if a secret service is likely available on Linux.
On Linux, the keyring crate requires a running secret service (gnome-keyring, kwallet, etc.) to function. This method checks for common indicators that a secret service is available.
On non-Linux platforms, this always returns true since they have built-in credential storage (macOS Keychain, Windows Credential Manager).
Sourcepub fn store(&self, credentials: &Credentials) -> Result<(), CloudError>
pub fn store(&self, credentials: &Credentials) -> Result<(), CloudError>
Stores credentials securely.
Uses file storage by default, or keychain if enabled and available.
Sourcepub fn load(&self) -> Result<Option<Credentials>, CloudError>
pub fn load(&self) -> Result<Option<Credentials>, CloudError>
Loads stored credentials.
Loads from keychain if enabled, otherwise from file storage. Also checks the alternate location for migration purposes.
Sourcepub fn delete(&self) -> Result<(), CloudError>
pub fn delete(&self) -> Result<(), CloudError>
Deletes stored credentials.
Removes credentials from both file and keyring storage to ensure complete cleanup regardless of how they were stored.
Sourcepub fn store_encryption_key(&self, key_hex: &str) -> Result<(), CloudError>
pub fn store_encryption_key(&self, key_hex: &str) -> Result<(), CloudError>
Stores the derived encryption key securely.
The encryption key is stored separately from credentials and should be a hex-encoded string of the derived key bytes.
Sourcepub fn load_encryption_key(&self) -> Result<Option<String>, CloudError>
pub fn load_encryption_key(&self) -> Result<Option<String>, CloudError>
Loads the stored encryption key.
Returns the hex-encoded encryption key, or None if not stored.
Sourcepub fn delete_encryption_key(&self) -> Result<(), CloudError>
pub fn delete_encryption_key(&self) -> Result<(), CloudError>
Deletes the stored encryption key.
Removes from both file and keyring to ensure complete cleanup.