• 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

93.22
/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 {
233✔
29
        Self {
233✔
30
            id,
233✔
31
            ver,
233✔
32
            doc_locator,
233✔
33
        }
233✔
34
    }
233✔
35

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

42
    /// Get Document Ver.
43
    #[must_use]
44
    pub fn ver(&self) -> &UuidV7 {
12✔
45
        &self.ver
12✔
46
    }
12✔
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
61
        )
62
    }
15✔
63
}
64

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

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

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

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

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

92
                DocumentRef {
136✔
93
                    id,
136✔
94
                    ver,
136✔
95
                    doc_locator,
136✔
96
                }
136✔
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)
136✔
107
    }
137✔
108
}
109

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