• 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

79.1
/rust/signed_doc/src/metadata/content_type.rs
1
//! Document Payload Content Type.
2

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

8
use strum::VariantArray;
9

10
/// Payload Content Type.
11
#[derive(Debug, Copy, Clone, PartialEq, Eq, VariantArray)]
12
pub enum ContentType {
13
    /// `application/cbor`
14
    Cbor,
15
    /// `application/cddl`
16
    Cddl,
17
    /// `application/json`
18
    Json,
19
    /// `application/json+schema`
20
    JsonSchema,
21
}
22

23
impl Display for ContentType {
24
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
190✔
25
        match self {
190✔
26
            Self::Cbor => write!(f, "application/cbor"),
11✔
NEW
27
            Self::Cddl => write!(f, "application/cddl"),
×
28
            Self::Json => write!(f, "application/json"),
179✔
NEW
29
            Self::JsonSchema => write!(f, "application/json+schema"),
×
30
        }
31
    }
190✔
32
}
33

34
impl FromStr for ContentType {
35
    type Err = anyhow::Error;
36

37
    fn from_str(s: &str) -> Result<Self, Self::Err> {
187✔
38
        match s {
187✔
39
            "application/cbor" => Ok(Self::Cbor),
187✔
40
            "application/cddl" => Ok(Self::Cddl),
179✔
41
            "application/json" => Ok(Self::Json),
177✔
42
            "application/json+schema" => Ok(Self::JsonSchema),
2✔
43
            _ => {
44
                anyhow::bail!(
×
45
                    "Unsupported Content Type: {s:?}, Supported only: {:?}",
×
46
                    ContentType::VARIANTS
×
47
                        .iter()
×
48
                        .map(ToString::to_string)
×
49
                        .collect::<Vec<_>>()
×
50
                )
51
            },
52
        }
53
    }
187✔
54
}
55

56
impl<'de> serde::Deserialize<'de> for ContentType {
57
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
61✔
58
    where D: serde::Deserializer<'de> {
61✔
59
        let s = String::deserialize(deserializer)?;
61✔
60
        FromStr::from_str(&s).map_err(serde::de::Error::custom)
61✔
61
    }
61✔
62
}
63

64
impl serde::Serialize for ContentType {
65
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
3✔
66
    where S: serde::Serializer {
3✔
67
        self.to_string().serialize(serializer)
3✔
68
    }
3✔
69
}
70

71
impl minicbor::Encode<()> for ContentType {
72
    fn encode<W: minicbor::encode::Write>(
121✔
73
        &self, e: &mut minicbor::Encoder<W>, _ctx: &mut (),
121✔
74
    ) -> Result<(), minicbor::encode::Error<W::Error>> {
121✔
75
        // encode as media types, not in CoAP Content-Formats
76
        e.str(self.to_string().as_str())?;
121✔
77
        Ok(())
121✔
78
    }
121✔
79
}
80

81
impl minicbor::Decode<'_, ()> for ContentType {
82
    fn decode(
119✔
83
        d: &mut minicbor::Decoder<'_>, _ctx: &mut (),
119✔
84
    ) -> Result<Self, minicbor::decode::Error> {
119✔
85
        let p = d.position();
119✔
86
        match d.int() {
119✔
87
            // CoAP Content Format JSON
NEW
88
            Ok(val) if val == minicbor::data::Int::from(50_u8) => Ok(Self::Json),
×
89
            // CoAP Content Format CBOR
NEW
90
            Ok(val) if val == minicbor::data::Int::from(60_u8) => Ok(Self::Cbor),
×
NEW
91
            Ok(val) => {
×
NEW
92
                Err(minicbor::decode::Error::message(format!(
×
NEW
93
                    "unsupported CoAP Content Formats value: {val}"
×
NEW
94
                )))
×
95
            },
96
            Err(_) => {
97
                d.set_position(p);
119✔
98
                d.str()?.parse().map_err(minicbor::decode::Error::message)
119✔
99
            },
100
        }
101
    }
119✔
102
}
103

104
#[cfg(test)]
105
mod tests {
106
    use super::*;
107

108
    #[test]
109
    fn content_type_string_test() {
1✔
110
        assert_eq!(
1✔
111
            ContentType::from_str("application/cbor").unwrap(),
1✔
112
            ContentType::Cbor
113
        );
114
        assert_eq!(
1✔
115
            ContentType::from_str("application/cddl").unwrap(),
1✔
116
            ContentType::Cddl
117
        );
118
        assert_eq!(
1✔
119
            ContentType::from_str("application/json").unwrap(),
1✔
120
            ContentType::Json
121
        );
122
        assert_eq!(
1✔
123
            ContentType::from_str("application/json+schema").unwrap(),
1✔
124
            ContentType::JsonSchema
125
        );
126
        assert_eq!(
1✔
127
            "application/cbor".parse::<ContentType>().unwrap(),
1✔
128
            ContentType::Cbor
129
        );
130
        assert_eq!(
1✔
131
            "application/cddl".parse::<ContentType>().unwrap(),
1✔
132
            ContentType::Cddl
133
        );
134
        assert_eq!(
1✔
135
            "application/json".parse::<ContentType>().unwrap(),
1✔
136
            ContentType::Json
137
        );
138
        assert_eq!(
1✔
139
            "application/json+schema".parse::<ContentType>().unwrap(),
1✔
140
            ContentType::JsonSchema
141
        );
142
    }
1✔
143
}
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