1use ruma_common::{
2 IdParseError, canonical_json::CanonicalJsonFieldError, serde::Base64DecodeError,
3};
4use thiserror::Error;
5
6use crate::Ed25519VerificationError;
7
8#[derive(Debug, Error)]
10#[non_exhaustive]
11pub enum JsonError {
12 #[error("PDU is larger than maximum of 65535 bytes")]
14 PduTooLarge,
15
16 #[error(transparent)]
18 Field(#[from] CanonicalJsonFieldError),
19
20 #[error(transparent)]
22 Serde(#[from] serde_json::Error),
23}
24
25#[derive(Debug, Error)]
27#[non_exhaustive]
28pub enum VerificationError {
29 #[error("Invalid JSON: {0}")]
31 Json(JsonError),
32
33 #[error("Could not parse base64-encoded signature at `path`: {source}")]
35 InvalidBase64Signature {
36 path: String,
38
39 #[source]
41 source: Base64DecodeError,
42 },
43
44 #[error("Could not parse {identifier_type}: {source}")]
46 ParseIdentifier {
47 identifier_type: &'static str,
49
50 #[source]
52 source: IdParseError,
53 },
54
55 #[error("signature uses an unsupported algorithm")]
57 UnsupportedAlgorithm,
58
59 #[error("Could not find signatures for entity {0:?}")]
61 NoSignaturesForEntity(String),
62
63 #[error("Could not find public keys for entity {0:?}")]
65 NoPublicKeysForEntity(String),
66
67 #[error("Could not find supported signature for entity {0:?}")]
69 NoSupportedSignatureForEntity(String),
70
71 #[error(transparent)]
73 Ed25519(#[from] Ed25519VerificationError),
74}
75
76impl<T> From<T> for VerificationError
77where
78 T: Into<JsonError>,
79{
80 fn from(value: T) -> Self {
81 Self::Json(value.into())
82 }
83}