• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / catalyst-libs / 16220495465

11 Jul 2025 12:52PM UTC coverage: 68.837% (+3.1%) from 65.707%
16220495465

Pull #338

github

web-flow
Merge 2d4d63344 into 5c081f7d2
Pull Request #338: feat(rust/signed-doc): Implement new Catalyst Signed Doc

2936 of 3144 new or added lines in 39 files covered. (93.38%)

45 existing lines in 10 files now uncovered.

12920 of 18769 relevant lines covered (68.84%)

2349.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/rust/signed_doc/src/metadata/content_encoding.rs
1
//! Document Payload Content Encoding.
2

3
use std::{
4
    fmt::{Display, Formatter},
5
    str::FromStr,
6
};
7

8
/// IANA `CoAP` Content Encoding.
9
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
10
pub enum ContentEncoding {
11
    /// Brotli compression.format.
12
    Brotli,
13
}
14

15
impl ContentEncoding {
16
    /// Compress a Brotli payload
17
    ///
18
    /// # Errors
19
    /// Returns compression failure
20
    pub fn encode(self, mut payload: &[u8]) -> anyhow::Result<Vec<u8>> {
37✔
21
        match self {
37✔
22
            Self::Brotli => {
37✔
23
                let brotli_params = brotli::enc::BrotliEncoderParams::default();
37✔
24
                let mut buf = Vec::new();
37✔
25
                brotli::BrotliCompress(&mut payload, &mut buf, &brotli_params)?;
37✔
26
                Ok(buf)
37✔
27
            },
28
        }
29
    }
37✔
30

31
    /// Decompress a Brotli payload
32
    ///
33
    /// # Errors
34
    ///  Returns decompression failure
35
    pub fn decode(self, mut payload: &[u8]) -> anyhow::Result<Vec<u8>> {
60✔
36
        match self {
60✔
37
            Self::Brotli => {
60✔
38
                let mut buf = Vec::new();
60✔
39
                brotli::BrotliDecompress(&mut payload, &mut buf)?;
60✔
40
                Ok(buf)
59✔
41
            },
42
        }
43
    }
60✔
44
}
45

46
impl Display for ContentEncoding {
47
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
77✔
48
        match self {
77✔
49
            Self::Brotli => write!(f, "br"),
77✔
50
        }
77✔
51
    }
77✔
52
}
53

54
impl FromStr for ContentEncoding {
55
    type Err = anyhow::Error;
56

57
    fn from_str(encoding: &str) -> Result<Self, Self::Err> {
77✔
58
        match encoding {
77✔
59
            "br" => Ok(ContentEncoding::Brotli),
77✔
60
            _ => anyhow::bail!("Unsupported Content Encoding: {encoding:?}"),
×
61
        }
62
    }
77✔
63
}
64

65
impl<'de> serde::Deserialize<'de> for ContentEncoding {
66
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
36✔
67
    where D: serde::Deserializer<'de> {
36✔
68
        let s = String::deserialize(deserializer)?;
36✔
69
        FromStr::from_str(&s).map_err(serde::de::Error::custom)
36✔
70
    }
36✔
71
}
72

73
impl serde::Serialize for ContentEncoding {
NEW
74
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
×
NEW
75
    where S: serde::Serializer {
×
NEW
76
        self.to_string().serialize(serializer)
×
NEW
77
    }
×
78
}
79

80
impl minicbor::Encode<()> for ContentEncoding {
81
    fn encode<W: minicbor::encode::Write>(
40✔
82
        &self, e: &mut minicbor::Encoder<W>, _ctx: &mut (),
40✔
83
    ) -> Result<(), minicbor::encode::Error<W::Error>> {
40✔
84
        e.str(self.to_string().as_str())?;
40✔
85
        Ok(())
40✔
86
    }
40✔
87
}
88

89
impl minicbor::Decode<'_, ()> for ContentEncoding {
90
    fn decode(
42✔
91
        d: &mut minicbor::Decoder<'_>, _ctx: &mut (),
42✔
92
    ) -> Result<Self, minicbor::decode::Error> {
42✔
93
        d.str()?.parse().map_err(minicbor::decode::Error::message)
42✔
94
    }
42✔
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc