use super::cert;
#[derive(Debug)]
pub enum PgpError {
Error(String),
VerificationError(VerificationError),
CertError(cert::error::CertError),
}
#[derive(Debug)]
#[non_exhaustive]
pub enum VerificationError {
Error(String),
MissingKey {
fingerprint: Vec<crate::openpgp::cert::Fingerprint>,
},
}
impl std::error::Error for VerificationError {}
impl std::fmt::Display for VerificationError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
VerificationError::MissingKey { fingerprint } => match fingerprint.len() {
0 => write!(f, "missing key for signature"),
1 => write!(f, "missing key for signature: {}", fingerprint[0]),
2.. => write!(f, "missing keys for signature: {fingerprint:?}"),
},
VerificationError::Error(e) => write!(f, "{e}"),
}
}
}
impl From<sequoia_openpgp::parse::stream::VerificationError<'_>> for VerificationError {
fn from(value: sequoia_openpgp::parse::stream::VerificationError<'_>) -> Self {
match value {
sequoia_openpgp::parse::stream::VerificationError::MissingKey { sig } => {
Self::MissingKey {
fingerprint: sig
.issuer_fingerprints()
.cloned()
.map(crate::openpgp::cert::Fingerprint)
.collect(),
}
}
_ => Self::Error(value.to_string()),
}
}
}
impl std::fmt::Display for PgpError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PgpError::Error(e) => write!(f, "{e}"),
PgpError::VerificationError(ve) => write!(f, "verification error - {ve}"),
PgpError::CertError(e) => write!(f, "{e}"),
}
}
}
impl std::error::Error for PgpError {}
impl PgpError {
pub(crate) fn from(error: impl std::fmt::Display) -> Self {
Self::Error(error.to_string())
}
}
impl From<cert::error::RevocationError> for PgpError {
fn from(error: cert::error::RevocationError) -> Self {
Self::CertError(cert::error::CertError::RevocationError(error))
}
}
#[derive(Debug)]
pub enum Error {
Pgp(PgpError),
AsyncTask(tokio::task::JoinError),
IO(std::io::Error),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Pgp(e) => e.fmt(f),
Self::AsyncTask(e) => e.fmt(f),
Self::IO(e) => e.fmt(f),
}
}
}
impl std::error::Error for Error {}
impl From<PgpError> for Error {
fn from(value: PgpError) -> Self {
Self::Pgp(value)
}
}
impl From<tokio::task::JoinError> for Error {
fn from(value: tokio::task::JoinError) -> Self {
Self::AsyncTask(value)
}
}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Self::IO(value)
}
}