1use thiserror::Error;
6
7pub type Result<T> = std::result::Result<T, Error>;
9
10#[derive(Error, Debug)]
15#[allow(missing_docs)]
16pub enum Error {
17 #[error("Cryptographic error: {0}")]
19 Crypto(String),
20
21 #[error("Key derivation failed: {0}")]
23 KeyDerivation(String),
24
25 #[error("Encryption failed: {0}")]
27 Encryption(String),
28
29 #[error("𓁧 Anubis's seal cannot be broken: {0}")]
31 Decryption(String),
32
33 #[error("Vault error: {0}")]
35 Vault(String),
36
37 #[error("Secret not found: {0}")]
39 SecretNotFound(String),
40
41 #[error("Secret already exists: {0}")]
43 SecretExists(String),
44
45 #[error("🜏 Anubis's sacred chamber has not been initialized at {0}")]
47 VaultNotInitialized(String),
48
49 #[error("🜏 Anubis's vault already guards this path: {0}")]
51 VaultExists(String),
52
53 #[error("🜏 Ancient seal version mismatch: found {got}, expected {expected}")]
55 InvalidVaultVersion { got: u32, expected: u32 },
56
57 #[error("I/O error: {0}")]
59 Io(#[from] std::io::Error),
60
61 #[error("Serialization error: {0}")]
63 Serialization(String),
64
65 #[error("Deserialization error: {0}")]
67 Deserialization(String),
68
69 #[error("Invalid input: {0}")]
71 InvalidInput(String),
72
73 #[error("𓋹 The guardian Anubis denies passage: {0}")]
75 AuthenticationFailed(String),
76
77 #[error("𓋹 Only those chosen by Anubis may enter: {0}")]
79 PermissionDenied(String),
80
81 #[error("{0}")]
83 Other(String),
84}
85
86impl From<argon2::Error> for Error {
87 fn from(err: argon2::Error) -> Self {
88 Error::KeyDerivation(err.to_string())
89 }
90}
91
92impl From<rmp_serde::encode::Error> for Error {
93 fn from(err: rmp_serde::encode::Error) -> Self {
94 Error::Serialization(err.to_string())
95 }
96}
97
98impl From<rmp_serde::decode::Error> for Error {
99 fn from(err: rmp_serde::decode::Error) -> Self {
100 Error::Deserialization(err.to_string())
101 }
102}
103
104impl From<chacha20poly1305::Error> for Error {
105 fn from(_: chacha20poly1305::Error) -> Self {
106 Error::AuthenticationFailed(
107 "Incorrect password or corrupted vault file. \
108 Anubis guards this chamber with unyielding resolve.".to_string()
109 )
110 }
111}
112
113impl From<serde_json::Error> for Error {
114 fn from(err: serde_json::Error) -> Self {
115 Error::Serialization(err.to_string())
116 }
117}