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

input-output-hk / catalyst-libs / 14342693064

08 Apr 2025 08:12PM UTC coverage: 65.188% (-0.2%) from 65.344%
14342693064

Pull #271

github

web-flow
Merge 712501d4b into 37f764449
Pull Request #271: fix(rust/signed-doc): Update DocumentRef to require version field

87 of 90 new or added lines in 5 files covered. (96.67%)

43 existing lines in 3 files now uncovered.

10537 of 16164 relevant lines covered (65.19%)

2692.6 hits per line

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

85.71
/rust/signed_doc/src/metadata/document_ref.rs
1
//! Catalyst Signed Document Metadata.
2

3
use std::fmt::Display;
4

5
use coset::cbor::Value;
6

7
use super::{utils::CborUuidV7, UuidV7};
8

9
/// Reference to a Document.
10
#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
11
pub struct DocumentRef {
12
    /// Reference to the Document Id
13
    pub id: UuidV7,
14
    /// Reference to the Document Ver
15
    pub ver: UuidV7,
16
}
17

18
impl Display for DocumentRef {
19
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10✔
20
        write!(f, "id: {}, ver: {}", self.id, self.ver)
10✔
21
    }
10✔
22
}
23

24
impl TryFrom<DocumentRef> for Value {
25
    type Error = anyhow::Error;
26

27
    fn try_from(value: DocumentRef) -> Result<Self, Self::Error> {
76✔
28
        Ok(Value::Array(vec![
76✔
29
            Value::try_from(CborUuidV7(value.id))?,
76✔
30
            Value::try_from(CborUuidV7(value.ver))?,
76✔
31
        ]))
32
    }
76✔
33
}
34

35
impl TryFrom<&Value> for DocumentRef {
36
    type Error = anyhow::Error;
37

38
    #[allow(clippy::indexing_slicing)]
39
    fn try_from(val: &Value) -> anyhow::Result<DocumentRef> {
6✔
40
        let Some(array) = val.as_array() else {
6✔
NEW
41
            anyhow::bail!("Document Reference must be either a single UUID or an array of two");
×
42
        };
43
        anyhow::ensure!(
6✔
44
            array.len() == 2,
6✔
NEW
45
            "Document Reference array of two UUIDs was expected"
×
46
        );
47
        let CborUuidV7(id) = CborUuidV7::try_from(&array[0])?;
6✔
48
        let CborUuidV7(ver) = CborUuidV7::try_from(&array[1])?;
6✔
49
        anyhow::ensure!(
6✔
50
            ver >= id,
6✔
NEW
51
            "Document Reference Version can never be smaller than its ID"
×
52
        );
53
        Ok(DocumentRef { id, ver })
6✔
54
    }
6✔
55
}
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