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

input-output-hk / catalyst-libs / 16472695838

23 Jul 2025 01:55PM UTC coverage: 68.485% (+2.7%) from 65.758%
16472695838

Pull #338

github

web-flow
Merge 7f24efa25 into 11c6aff43
Pull Request #338: feat(rust/signed-doc): Implement new Catalyst Signed Doc

2727 of 2930 new or added lines in 38 files covered. (93.07%)

37 existing lines in 9 files now uncovered.

12678 of 18512 relevant lines covered (68.49%)

2238.4 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>> {
31✔
21
        match self {
31✔
22
            Self::Brotli => {
31✔
23
                let brotli_params = brotli::enc::BrotliEncoderParams::default();
31✔
24
                let mut buf = Vec::new();
31✔
25
                brotli::BrotliCompress(&mut payload, &mut buf, &brotli_params)?;
31✔
26
                Ok(buf)
31✔
27
            },
28
        }
29
    }
31✔
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>> {
49✔
36
        match self {
49✔
37
            Self::Brotli => {
49✔
38
                let mut buf = Vec::new();
49✔
39
                brotli::BrotliDecompress(&mut payload, &mut buf)?;
49✔
40
                Ok(buf)
48✔
41
            },
42
        }
43
    }
49✔
44
}
45

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

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

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

65
impl<'de> serde::Deserialize<'de> for ContentEncoding {
66
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
30✔
67
    where D: serde::Deserializer<'de> {
30✔
68
        let s = String::deserialize(deserializer)?;
30✔
69
        FromStr::from_str(&s).map_err(serde::de::Error::custom)
30✔
70
    }
30✔
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>(
34✔
82
        &self, e: &mut minicbor::Encoder<W>, _ctx: &mut (),
34✔
83
    ) -> Result<(), minicbor::encode::Error<W::Error>> {
34✔
84
        e.str(self.to_string().as_str())?;
34✔
85
        Ok(())
34✔
86
    }
34✔
87
}
88

89
impl minicbor::Decode<'_, ()> for ContentEncoding {
90
    fn decode(
36✔
91
        d: &mut minicbor::Decoder<'_>, _ctx: &mut (),
36✔
92
    ) -> Result<Self, minicbor::decode::Error> {
36✔
93
        d.str()?.parse().map_err(minicbor::decode::Error::message)
36✔
94
    }
36✔
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