1#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum ArcError {
6 MissingTag(String),
8 InvalidTag(String),
10 InvalidCv(String),
12 InvalidInstance(u32),
14 UnsupportedAlgorithm(String),
16 NonContiguousChain {
18 missing: u32,
20 },
21 ChainTooLong(usize),
23 IncompleteSet {
26 instance: u32,
28 missing: &'static str,
30 },
31 Dns(String),
33 InvalidPublicKey(String),
35 SignatureMismatch {
37 header: &'static str,
39 instance: u32,
41 },
42 BodyHashMismatch,
45 InvalidBase64(String),
47 MalformedMessage,
50}
51
52impl std::fmt::Display for ArcError {
53 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54 match self {
55 Self::MissingTag(t) => write!(f, "missing required tag: {t}"),
56 Self::InvalidTag(t) => write!(f, "invalid tag: {t}"),
57 Self::InvalidCv(v) => write!(f, "invalid cv= value: {v}"),
58 Self::InvalidInstance(i) => {
59 write!(f, "invalid i= value: {i} (must be 1..=50)")
60 }
61 Self::UnsupportedAlgorithm(a) => write!(f, "unsupported algorithm: {a}"),
62 Self::NonContiguousChain { missing } => {
63 write!(f, "chain not contiguous from i=1; missing i={missing}")
64 }
65 Self::ChainTooLong(n) => {
66 write!(f, "chain too long: {n} sets (max 50 per RFC 8617 §4.2.1)")
67 }
68 Self::IncompleteSet { instance, missing } => {
69 write!(f, "incomplete ARC set i={instance}: missing {missing}")
70 }
71 Self::Dns(msg) => write!(f, "DNS lookup failed: {msg}"),
72 Self::InvalidPublicKey(msg) => write!(f, "invalid public key: {msg}"),
73 Self::SignatureMismatch { header, instance } => {
74 write!(f, "signature mismatch on {header} i={instance}")
75 }
76 Self::BodyHashMismatch => write!(f, "body hash (bh=) mismatch"),
77 Self::InvalidBase64(tag) => write!(f, "invalid base64 in tag: {tag}"),
78 Self::MalformedMessage => write!(f, "malformed message: no end-of-headers"),
79 }
80 }
81}
82
83impl std::error::Error for ArcError {}