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

input-output-hk / catalyst-libs / 16219415812

11 Jul 2025 11:55AM UTC coverage: 68.835%. First build
16219415812

Pull #418

github

web-flow
Merge b09bdeee6 into a8b219ddd
Pull Request #418: feat(rust/signed-doc): Apply deterministic CBOR decoding from `cbork-utils`

157 of 182 new or added lines in 7 files covered. (86.26%)

12919 of 18768 relevant lines covered (68.84%)

2337.1 hits per line

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

93.65
/rust/signed_doc/src/metadata/document_refs/doc_ref.rs
1
//! Document reference.
2

3
use std::fmt::Display;
4

5
use catalyst_types::uuid::{CborContext, UuidV7};
6
use cbork_utils::{array::Array, decode_context::DecodeCtx};
7
use minicbor::{Decode, Encode};
8

9
use super::doc_locator::DocLocator;
10

11
/// Number of item that should be in each document reference instance.
12
const DOC_REF_ARR_ITEM: u64 = 3;
13

14
/// Reference to a Document.
15
#[derive(Clone, Debug, PartialEq, Hash, Eq)]
16
pub struct DocumentRef {
17
    /// Reference to the Document Id
18
    id: UuidV7,
19
    /// Reference to the Document Ver
20
    ver: UuidV7,
21
    /// Document locator
22
    doc_locator: DocLocator,
23
}
24

25
impl DocumentRef {
26
    /// Create a new instance of document reference.
27
    #[must_use]
28
    pub fn new(id: UuidV7, ver: UuidV7, doc_locator: DocLocator) -> Self {
241✔
29
        Self {
241✔
30
            id,
241✔
31
            ver,
241✔
32
            doc_locator,
241✔
33
        }
241✔
34
    }
241✔
35

36
    /// Get Document Id.
37
    #[must_use]
38
    pub fn id(&self) -> &UuidV7 {
83✔
39
        &self.id
83✔
40
    }
83✔
41

42
    /// Get Document Ver.
43
    #[must_use]
44
    pub fn ver(&self) -> &UuidV7 {
5✔
45
        &self.ver
5✔
46
    }
5✔
47

48
    /// Get Document Locator.
49
    #[must_use]
50
    pub fn doc_locator(&self) -> &DocLocator {
5✔
51
        &self.doc_locator
5✔
52
    }
5✔
53
}
54

55
impl Display for DocumentRef {
56
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15✔
57
        write!(
15✔
58
            f,
15✔
59
            "id: {}, ver: {}, document_locator: {}",
15✔
60
            self.id, self.ver, self.doc_locator
15✔
61
        )
15✔
62
    }
15✔
63
}
64

65
impl Decode<'_, ()> for DocumentRef {
66
    fn decode(
151✔
67
        d: &mut minicbor::Decoder<'_>, _ctx: &mut (),
151✔
68
    ) -> Result<Self, minicbor::decode::Error> {
151✔
69
        const CONTEXT: &str = "DocumentRef decoding";
70

71
        let arr = Array::decode(d, &mut DecodeCtx::Deterministic)
151✔
72
            .map_err(|e| minicbor::decode::Error::message(format!("{CONTEXT}: {e}")))?;
151✔
73

74
        let doc_ref = match arr.as_slice() {
151✔
75
            [id_bytes, ver_bytes, locator_bytes] => {
151✔
76
                let id = UuidV7::decode(
151✔
77
                    &mut minicbor::Decoder::new(id_bytes.as_slice()),
151✔
78
                    &mut CborContext::Tagged,
151✔
79
                )
151✔
80
                .map_err(|e| e.with_message("Invalid ID UUIDv7"))?;
151✔
81

82
                let ver = UuidV7::decode(
150✔
83
                    &mut minicbor::Decoder::new(ver_bytes.as_slice()),
150✔
84
                    &mut CborContext::Tagged,
150✔
85
                )
150✔
86
                .map_err(|e| e.with_message("Invalid Ver UUIDv7"))?;
150✔
87

88
                let doc_locator = minicbor::Decoder::new(locator_bytes.as_slice())
150✔
89
                    .decode()
150✔
90
                    .map_err(|e| e.with_message("Failed to decode locator"))?;
150✔
91

92
                DocumentRef {
150✔
93
                    id,
150✔
94
                    ver,
150✔
95
                    doc_locator,
150✔
96
                }
150✔
97
            },
98
            _ => {
NEW
99
                return Err(minicbor::decode::Error::message(format!(
×
NEW
100
                    "{CONTEXT}: expected {DOC_REF_ARR_ITEM} items, found {}",
×
NEW
101
                    arr.len()
×
NEW
102
                )));
×
103
            },
104
        };
105

106
        Ok(doc_ref)
150✔
107
    }
151✔
108
}
109

110
impl Encode<()> for DocumentRef {
111
    fn encode<W: minicbor::encode::Write>(
170✔
112
        &self, e: &mut minicbor::Encoder<W>, ctx: &mut (),
170✔
113
    ) -> Result<(), minicbor::encode::Error<W::Error>> {
170✔
114
        e.array(DOC_REF_ARR_ITEM)?;
170✔
115
        self.id.encode(e, &mut CborContext::Tagged)?;
170✔
116
        self.ver.encode(e, &mut CborContext::Tagged)?;
170✔
117
        self.doc_locator.encode(e, ctx)?;
170✔
118
        Ok(())
170✔
119
    }
170✔
120
}
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