use thiserror::Error;
#[derive(Debug, Error, PartialEq, Eq)]
pub enum MessageError {
#[error("envelope is {size} bytes, exceeds the {max}-byte cap")]
EnvelopeTooLarge { size: usize, max: usize },
#[error("truncated envelope: {0}")]
Truncated(String),
#[error("unsupported envelope version {0}")]
UnsupportedVersion(u8),
#[error("unsupported compression id {0}")]
UnsupportedCompression(u8),
#[error("declared uncompressed length {declared} exceeds the {max}-byte cap")]
DecompressionBomb { declared: usize, max: usize },
#[error("decompressed length mismatch: expected {expected}, got {actual}")]
DecompressedLengthMismatch { expected: usize, actual: usize },
#[error("payload is {0} bytes, exceeds the u32 uncompressed_len field")]
PayloadTooLarge(usize),
#[error("codec error: {0}")]
Codec(String),
#[error("unsupported message type {0:#010x}")]
UnsupportedType(u32),
#[error("message type {0:#010x} is already registered")]
DuplicateType(u32),
#[error("G1 subgroup / non-identity check failed on the seal key material")]
InvalidPoint,
#[error("sender DID could not be resolved to an identity key")]
UnresolvableSender,
#[error("seal failed: {0}")]
SealFailed(String),
#[error("seal open failed (wrong key or tampered ciphertext/header)")]
OpenFailed,
#[error("BLS sender signature verification failed")]
BadSignature,
#[error("sealed inner header does not match the cleartext header (type-confusion / splice)")]
HeaderMismatch,
#[error("anti-replay check failed (duplicate, stale, or outside the freshness window)")]
Replay,
#[error("message expired (now > expires_at)")]
Expired,
#[error("expires_at exceeds the maximum message TTL")]
TtlTooLong,
}
pub type Result<T> = std::result::Result<T, MessageError>;