http_content_digest/
errors.rs

1#[derive(Debug, thiserror::Error)]
2pub enum DigestError {
3    #[error("Http body error")]
4    Body,
5
6    #[error("Mismatched content digest.")]
7    Mismatch,
8
9    #[error(transparent)]
10    ExtractHeader(#[from] ExtractHeaderError),
11
12    #[error("Algorithm not supported.")]
13    AlgorithmNotSupported,
14}
15
16#[derive(Debug, thiserror::Error)]
17pub enum ExtractHeaderError {
18    #[error("No {header_name} header found.")]
19    NoExist { header_name: &'static str },
20
21    #[error("Failed to convert header value into str: {0}")]
22    FailedToStr(http::header::ToStrError),
23
24    #[error(transparent)]
25    InvalidHeaderValue(Box<dyn std::error::Error + Sync + Send + 'static>),
26}
27
28#[derive(Debug, thiserror::Error)]
29#[error("Invalid Content-Digest header value.")]
30pub struct InvalidContentDigest;
31
32impl From<InvalidContentDigest> for ExtractHeaderError {
33    fn from(error: InvalidContentDigest) -> Self {
34        ExtractHeaderError::InvalidHeaderValue(Box::new(error))
35    }
36}
37
38impl From<sfv::Error> for ExtractHeaderError {
39    fn from(e: sfv::Error) -> Self {
40        ExtractHeaderError::InvalidHeaderValue(Box::new(e))
41    }
42}
43
44impl From<base64::DecodeError> for ExtractHeaderError {
45    fn from(value: base64::DecodeError) -> Self {
46        Self::InvalidHeaderValue(Box::new(value))
47    }
48}