1pub use crate::config::{CompressionConfigError, InnerCipherConfigError, KdfConfigError, OuterCipherConfigError};
4pub use crate::crypt::CryptographyError;
5#[cfg(feature = "save_kdbx4")]
6pub use crate::db::DatabaseSaveError;
7pub use crate::db::ParseColorError;
8pub use crate::db::{DatabaseIntegrityError, DatabaseOpenError};
9pub use crate::format::DatabaseVersionParseError;
10pub use crate::format::hmac_block_stream::BlockStreamError;
11pub use crate::format::kdb::KdbOpenError;
12pub use crate::format::kdbx3::{Kdbx3OpenError, Kdbx3OuterHeaderError};
13pub use crate::format::kdbx4::{Kdbx4InnerHeaderError, Kdbx4OpenError, Kdbx4OuterHeaderError};
14pub use crate::format::variant_dictionary::VariantDictionaryError;
15pub use crate::format::xml_db::parse::XmlParseError;
16#[cfg(feature = "challenge_response")]
17pub use crate::key::ChallengeResponseKeyError;
18pub use crate::key::DatabaseKeyError;
19
20#[derive(thiserror::Error, Debug)]
21pub enum Error {
22 #[error("std::io::Error {0}")]
23 Io(#[from] std::io::Error),
24
25 #[error("DatabaseError::RecycleBinDisabled")]
26 RecycleBinDisabled,
27
28 #[error("DatabaseError::RecycleBinAlreadyExists")]
29 RecycleBinAlreadyExists,
30
31 #[error("DatabaseOpenError {0}")]
32 DatabaseOpenError(#[from] DatabaseOpenError),
33
34 #[cfg(feature = "save_kdbx4")]
35 #[error("DatabaseSaveError {0}")]
36 DatabaseSaveError(#[from] DatabaseSaveError),
37
38 #[cfg(feature = "totp")]
39 #[error("DbOtpError {0}")]
40 DbOtpError(#[from] crate::db::otp::TOTPError),
41
42 #[error("OuterCipherConfigError {0}")]
43 OuterCipherConfigError(#[from] OuterCipherConfigError),
44
45 #[error("InnerCipherConfigError {0}")]
46 InnerCipherConfigError(#[from] InnerCipherConfigError),
47
48 #[error("CompressionConfigError {0}")]
49 CompressionConfigError(#[from] CompressionConfigError),
50
51 #[error("KdfConfigError {0}")]
52 KdfConfigError(#[from] KdfConfigError),
53
54 #[error("CryptographyError {0}")]
55 CryptographyError(#[from] CryptographyError),
56
57 #[error("BlockStreamError {0}")]
58 BlockStreamError(#[from] BlockStreamError),
59
60 #[error("VariantDictionaryError {0}")]
61 VariantDictionaryError(#[from] VariantDictionaryError),
62
63 #[error("XmlParseError {0}")]
64 XmlParseError(#[from] XmlParseError),
65
66 #[error("ParseColorError {0}")]
67 ParseColorError(#[from] ParseColorError),
68
69 #[error("ParseIconIdError {}", icon_id)]
70 ParseIconIdError { icon_id: usize },
71
72 #[cfg(feature = "merge")]
73 #[error("MergeError {0}")]
74 MergeError(#[from] crate::db::merge::MergeError),
75
76 #[error("String error: {0}")]
77 String(String),
78}
79
80impl From<&str> for Error {
81 fn from(s: &str) -> Self {
82 Error::String(s.to_string())
83 }
84}
85
86impl From<String> for Error {
87 fn from(s: String) -> Self {
88 Error::String(s)
89 }
90}
91
92impl From<&String> for Error {
93 fn from(s: &String) -> Self {
94 Error::String(s.clone())
95 }
96}
97
98pub type Result<T, E = Error> = std::result::Result<T, E>;
99
100pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
101
102mod conversions {
104 use super::{
105 BlockStreamError, CompressionConfigError, CryptographyError, DatabaseIntegrityError, DatabaseOpenError, InnerCipherConfigError,
106 KdfConfigError, OuterCipherConfigError, VariantDictionaryError, XmlParseError,
107 };
108
109 impl From<CryptographyError> for DatabaseOpenError {
110 fn from(e: CryptographyError) -> Self {
111 DatabaseIntegrityError::from(e).into()
112 }
113 }
114
115 impl From<BlockStreamError> for DatabaseOpenError {
116 fn from(e: BlockStreamError) -> Self {
117 DatabaseIntegrityError::from(e).into()
118 }
119 }
120
121 impl From<XmlParseError> for DatabaseOpenError {
122 fn from(e: XmlParseError) -> Self {
123 DatabaseIntegrityError::from(e).into()
124 }
125 }
126
127 impl From<InnerCipherConfigError> for DatabaseOpenError {
128 fn from(e: InnerCipherConfigError) -> Self {
129 DatabaseIntegrityError::from(e).into()
130 }
131 }
132
133 impl From<OuterCipherConfigError> for DatabaseOpenError {
134 fn from(e: OuterCipherConfigError) -> Self {
135 DatabaseIntegrityError::from(e).into()
136 }
137 }
138
139 impl From<KdfConfigError> for DatabaseOpenError {
140 fn from(e: KdfConfigError) -> Self {
141 DatabaseIntegrityError::from(e).into()
142 }
143 }
144
145 impl From<VariantDictionaryError> for DatabaseOpenError {
146 fn from(e: VariantDictionaryError) -> Self {
147 DatabaseIntegrityError::from(e).into()
148 }
149 }
150
151 impl From<CompressionConfigError> for DatabaseOpenError {
152 fn from(e: CompressionConfigError) -> Self {
153 DatabaseIntegrityError::from(e).into()
154 }
155 }
156}