pub type DntResult<T> = Result<T, DntError>;
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum DntError {
#[error("invalid DNT container")]
InvalidFormat,
#[error("unsupported DNT envelope version")]
UnsupportedVersion,
#[error("DNT payload exceeds configured limit")]
PayloadTooLarge,
#[error("DNT flags are invalid")]
InvalidFlags,
#[error("DNT context mismatch")]
ContextMismatch,
#[error("DNT key is unavailable")]
KeyUnavailable,
#[error("DNT authentication failed")]
AuthenticationFailed,
#[error("DNT codec is unavailable")]
CodecUnavailable,
#[error("DNT codec failed")]
CodecFailed,
#[error("DNT I/O failed")]
Io,
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum DntKeyError {
#[error("DNT key was not found")]
NotFound,
#[error("DNT key provider is unavailable")]
Unavailable,
#[error("DNT key material is invalid")]
InvalidKey,
#[error("DNT key is not valid for the requested context")]
Forbidden,
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum CodecError {
#[error("DNT codec encode failed")]
EncodeFailed,
#[error("DNT codec decode failed")]
DecodeFailed,
#[error("DNT codec payload is too large")]
PayloadTooLarge,
}
impl From<DntKeyError> for DntError {
fn from(value: DntKeyError) -> Self {
match value {
DntKeyError::NotFound | DntKeyError::Unavailable => Self::KeyUnavailable,
DntKeyError::InvalidKey => Self::KeyUnavailable,
DntKeyError::Forbidden => Self::ContextMismatch,
}
}
}
impl From<CodecError> for DntError {
fn from(_: CodecError) -> Self {
Self::CodecFailed
}
}