1use thiserror::Error;
7
8#[derive(Error, Debug)]
10pub enum Error {
11 #[error("Cryptographic operation failed: {0}")]
13 Crypto(String),
14
15 #[error("Certificate parsing failed: {0}")]
17 Parse(String),
18
19 #[error("Invalid password or key")]
21 InvalidPassword,
22
23 #[error("Key not found: {0}")]
25 KeyNotFound(String),
26
27 #[error("Signature verification failed")]
29 VerificationFailed,
30
31 #[error("Cannot merge identical keys")]
33 SameKeyError,
34
35 #[error("I/O error: {0}")]
37 Io(#[from] std::io::Error),
38
39 #[error("Invalid input: {0}")]
41 InvalidInput(String),
42
43 #[error("Unsupported algorithm: {0}")]
45 UnsupportedAlgorithm(String),
46
47 #[error("Key has expired")]
49 KeyExpired,
50
51 #[error("Key has been revoked")]
53 KeyRevoked,
54
55 #[error("No suitable encryption subkey found")]
57 NoEncryptionSubkey,
58
59 #[error("No suitable signing subkey found")]
61 NoSigningSubkey,
62
63 #[error("No suitable authentication subkey found")]
65 NoAuthenticationSubkey,
66
67 #[error("Certificate does not contain secret key material")]
69 NoSecretKey,
70
71 #[error("Malformed armored data: {0}")]
73 MalformedArmor(String),
74
75 #[error("User ID not found: {0}")]
77 UidNotFound(String),
78
79 #[cfg(feature = "keystore")]
81 #[error("Database error: {0}")]
82 Database(#[from] rusqlite::Error),
83
84 #[error("Network error: {0}")]
86 Network(String),
87
88 #[error("OpenPGP error: {0}")]
90 OpenPgp(#[from] pgp::errors::Error),
91
92 #[error("Error: {0}")]
94 Generic(#[from] anyhow::Error),
95
96 #[cfg(feature = "card")]
98 #[error("Smart card error: {0}")]
99 Card(#[from] crate::card::CardError),
100}
101
102pub type Result<T> = std::result::Result<T, Error>;
104
105impl From<String> for Error {
106 fn from(s: String) -> Self {
107 Error::Crypto(s)
108 }
109}
110
111impl From<&str> for Error {
112 fn from(s: &str) -> Self {
113 Error::Crypto(s.to_string())
114 }
115}