1pub type DntResult<T> = Result<T, DntError>;
5
6#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
8pub enum DntError {
9 #[error("invalid DNT container")]
11 InvalidFormat,
12 #[error("unsupported DNT envelope version")]
14 UnsupportedVersion,
15 #[error("DNT payload exceeds configured limit")]
17 PayloadTooLarge,
18 #[error("DNT flags are invalid")]
20 InvalidFlags,
21 #[error("DNT context mismatch")]
23 ContextMismatch,
24 #[error("DNT key is unavailable")]
26 KeyUnavailable,
27 #[error("DNT authentication failed")]
29 AuthenticationFailed,
30 #[error("DNT codec is unavailable")]
32 CodecUnavailable,
33 #[error("DNT codec failed")]
35 CodecFailed,
36 #[error("DNT I/O failed")]
38 Io,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
43pub enum DntKeyError {
44 #[error("DNT key was not found")]
46 NotFound,
47 #[error("DNT key provider is unavailable")]
49 Unavailable,
50 #[error("DNT key material is invalid")]
52 InvalidKey,
53 #[error("DNT key is not valid for the requested context")]
55 Forbidden,
56}
57
58#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
60pub enum CodecError {
61 #[error("DNT codec encode failed")]
63 EncodeFailed,
64 #[error("DNT codec decode failed")]
66 DecodeFailed,
67 #[error("DNT codec payload is too large")]
69 PayloadTooLarge,
70}
71
72impl From<DntKeyError> for DntError {
73 fn from(value: DntKeyError) -> Self {
74 match value {
75 DntKeyError::NotFound | DntKeyError::Unavailable => Self::KeyUnavailable,
76 DntKeyError::InvalidKey => Self::KeyUnavailable,
77 DntKeyError::Forbidden => Self::ContextMismatch,
78 }
79 }
80}
81
82impl From<CodecError> for DntError {
83 fn from(_: CodecError) -> Self {
84 Self::CodecFailed
85 }
86}