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

input-output-hk / catalyst-libs / 16646523141

31 Jul 2025 10:28AM UTC coverage: 67.341% (+3.8%) from 63.544%
16646523141

push

github

web-flow
feat(rust/signed-doc): Implement new Catalyst Signed Doc (#338)

* chore: add new line to open pr

Signed-off-by: bkioshn <bkioshn@gmail.com>

* chore: revert

Signed-off-by: bkioshn <bkioshn@gmail.com>

* feat(rust/signed-doc): add new type `DocType` (#339)

* feat(signed-doc): add new type DocType

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): add conversion policy

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): doc type

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): doc type error

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): seperate test

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): format

Signed-off-by: bkioshn <bkioshn@gmail.com>

---------

Signed-off-by: bkioshn <bkioshn@gmail.com>

* feat(rust/signed-doc): Add initial decoding tests for the Catalyst Signed Documents (#349)

* wip

* wip

* fix fmt

* fix spelling

* fix clippy

* fix(rust/signed-doc): Apply new `DocType` (#347)

* feat(signed-doc): add new type DocType

Signed-off-by: bkioshn <bkioshn@gmail.com>

* wip: apply doctype

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): add more function to DocType

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): map old doctype to new doctype

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): add eq to uuidv4

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): fix validator

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): minor fixes

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(catalyst-types): add hash to uuidv4

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): decoding test

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): doctype

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(signed-doc): minor fixes

Signed-off-by: bkioshn <bkioshn@gmail.com>

* chore(sign-doc): fix comment

Signed-off-by: bkioshn <bkioshn@gmail.com>

* fix(catalyst-types): add froms... (continued)

2453 of 2675 new or added lines in 38 files covered. (91.7%)

19 existing lines in 7 files now uncovered.

11312 of 16798 relevant lines covered (67.34%)

2525.16 hits per line

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

88.1
/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 => {
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 => {
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
        }
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

© 2025 Coveralls, Inc