use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Cryptographic operation failed: {0}")]
Crypto(String),
#[error("Certificate parsing failed: {0}")]
Parse(String),
#[error("Invalid password or key")]
InvalidPassword,
#[error("Key not found: {0}")]
KeyNotFound(String),
#[error("Signature verification failed")]
VerificationFailed,
#[error("Cannot merge identical keys")]
SameKeyError,
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Invalid input: {0}")]
InvalidInput(String),
#[error("Unsupported algorithm: {0}")]
UnsupportedAlgorithm(String),
#[error("Key has expired")]
KeyExpired,
#[error("Key has been revoked")]
KeyRevoked,
#[error("No suitable encryption subkey found")]
NoEncryptionSubkey,
#[error("No suitable signing subkey found")]
NoSigningSubkey,
#[error("No suitable authentication subkey found")]
NoAuthenticationSubkey,
#[error("Certificate does not contain secret key material")]
NoSecretKey,
#[error("Malformed armored data: {0}")]
MalformedArmor(String),
#[error("User ID not found: {0}")]
UidNotFound(String),
#[cfg(feature = "keystore")]
#[error("Database error: {0}")]
Database(#[from] rusqlite::Error),
#[error("Network error: {0}")]
Network(String),
#[error("OpenPGP error: {0}")]
OpenPgp(#[from] pgp::errors::Error),
#[error("Error: {0}")]
Generic(#[from] anyhow::Error),
#[cfg(feature = "card")]
#[error("Smart card error: {0}")]
Card(#[from] crate::card::CardError),
}
pub type Result<T> = std::result::Result<T, Error>;
impl From<String> for Error {
fn from(s: String) -> Self {
Error::Crypto(s)
}
}
impl From<&str> for Error {
fn from(s: &str) -> Self {
Error::Crypto(s.to_string())
}
}