kdbx_rs/
errors.rs

1//! Error types for kdbx-rs
2
3pub use crate::binary::errors::{HeaderError, OpenError, UnlockError, WriteError};
4pub use crate::binary::FailedUnlock;
5pub use crate::crypto::KeyGenerationError;
6pub use crate::stream::random::InnerStreamError;
7pub use crate::xml::parse::Error as XmlReadError;
8pub use crate::xml::serialize::Error as XmlWriteError;
9use thiserror::Error;
10
11#[derive(Error, Debug)]
12/// Wrapper error type for this library
13pub enum Error {
14    /// Failed to open a KDBX file
15    #[error("Could not open database: {0}")]
16    Open(#[from] OpenError),
17    /// Failed unlocking a KDBX file
18    #[error("Could not unlock database: {0}")]
19    Unlock(#[from] UnlockError),
20    /// Failed to write a KDBX file
21    #[error("Could not write database: {0}")]
22    Write(#[from] WriteError),
23    /// Failed parsing database XML
24    #[error("Failed to parse database XML: {0}")]
25    XmlRead(#[from] XmlReadError),
26    /// Failed writing database XML
27    #[error("Failed to write database XML: {0}")]
28    XmlWrite(#[from] XmlWriteError),
29    /// Failed generating crypto keys
30    #[error("Failed to create encryption keys")]
31    KeyGeneration(#[from] KeyGenerationError),
32}
33
34impl From<FailedUnlock> for Error {
35    fn from(funlock: FailedUnlock) -> Error {
36        Error::Unlock(funlock.1)
37    }
38}