age-vault 0.1.0

A secure vault for managing age-encrypted accounts and data.
Documentation
//! Error types for the vault.
//!
//! This module defines the [`Error`] enum covering all possible failures
//! (I/O, database, crypto, serialization, etc.) and a [`Result`] type alias.

use thiserror::Error;

/// Main error type for the age-vault crate.
///
/// All fallible operations return a `Result<T, Error>`. Variants wrap errors
/// from underlying dependencies or provide specific vault-related failures.
///
/// # Examples
///
/// ```
/// use age_vault::Error;
///
/// fn might_fail() -> Result<(), Error> {
///     Err(Error::AccountNotFound("alice".into()))
/// }
/// ```
#[derive(Debug, Error)]
pub enum Error {
    /// I/O error (e.g., file not found, permission denied).
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),

    /// Database error from neuxdb.
    #[error("Database error: {0}")]
    Db(#[from] neuxdb::Error),

    /// Configuration error from neuxcfg.
    #[error("Configuration error: {0}")]
    Config(#[from] neuxcfg::NeuxcfgError),

    /// Cryptographic error from age_crypto.
    #[error("Crypto error: {0}")]
    Crypto(#[from] age_crypto::Error),

    /// Key generation error from age_setup.
    #[error("Key generation error: {0}")]
    KeyGen(#[from] age_setup::Error),

    /// Key derivation function error (Argon2).
    #[error("KDF error: {0}")]
    Kdf(String),

    /// Serialization/deserialization error.
    #[error("Serialization error: {0}")]
    Serde(#[from] serde_json::Error),

    /// Requested account does not exist.
    #[error("Account not found: {0}")]
    AccountNotFound(String),

    /// Account with the same name already exists.
    #[error("Account already exists: {0}")]
    AccountExists(String),

    /// The provided master password is incorrect.
    #[error("Invalid master password")]
    InvalidMasterPassword,

    /// Decryption operation failed.
    #[error("Decryption failed: {0}")]
    DecryptionFailed(String),

    /// Encryption operation failed.
    #[error("Encryption failed: {0}")]
    EncryptionFailed(String),
}

/// Convenient result type alias using [`Error`].
///
/// This is the standard result type used throughout the crate.
pub type Result<T> = std::result::Result<T, Error>;

impl From<argon2::password_hash::Error> for Error {
    fn from(err: argon2::password_hash::Error) -> Self {
        Error::Kdf(err.to_string())
    }
}