use ruma_common::{
IdParseError, canonical_json::CanonicalJsonFieldError, serde::Base64DecodeError,
};
use thiserror::Error;
use crate::Ed25519VerificationError;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum JsonError {
#[error("PDU is larger than maximum of 65535 bytes")]
PduTooLarge,
#[error(transparent)]
Field(#[from] CanonicalJsonFieldError),
#[error(transparent)]
Serde(#[from] serde_json::Error),
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum VerificationError {
#[error("Invalid JSON: {0}")]
Json(JsonError),
#[error("Could not parse base64-encoded signature at `path`: {source}")]
InvalidBase64Signature {
path: String,
#[source]
source: Base64DecodeError,
},
#[error("Could not parse {identifier_type}: {source}")]
ParseIdentifier {
identifier_type: &'static str,
#[source]
source: IdParseError,
},
#[error("signature uses an unsupported algorithm")]
UnsupportedAlgorithm,
#[error("Could not find signatures for entity {0:?}")]
NoSignaturesForEntity(String),
#[error("Could not find public keys for entity {0:?}")]
NoPublicKeysForEntity(String),
#[error("Could not find supported signature for entity {0:?}")]
NoSupportedSignatureForEntity(String),
#[error(transparent)]
Ed25519(#[from] Ed25519VerificationError),
}
impl<T> From<T> for VerificationError
where
T: Into<JsonError>,
{
fn from(value: T) -> Self {
Self::Json(value.into())
}
}