Skip to content

Commit ced1a74

Browse files
committed
Cleanup signed-doc API, make some needed for cat-gatewat getters
1 parent eaf071e commit ced1a74

File tree

4 files changed

+70
-26
lines changed

4 files changed

+70
-26
lines changed

rust/signed_doc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ license.workspace = true
1111
workspace = true
1212

1313
[dependencies]
14-
catalyst-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250122-00" }
14+
catalyst-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250124-00" }
1515
anyhow = "1.0.95"
1616
serde = { version = "1.0.217", features = ["derive"] }
1717
serde_json = "1.0.134"

rust/signed_doc/src/metadata/document_ref.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,24 @@ use super::{decode_cbor_uuid, encode_cbor_uuid, UuidV7};
55

66
/// Reference to a Document.
77
#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
8-
#[serde(untagged)]
9-
pub enum DocumentRef {
10-
/// Reference to the latest document
11-
Latest {
12-
/// Document ID UUID
13-
id: UuidV7,
14-
},
15-
/// Reference to the specific document version
16-
WithVer {
17-
/// Document ID UUID,
18-
id: UuidV7,
19-
/// Document Ver UUID
20-
ver: UuidV7,
21-
},
8+
pub struct DocumentRef {
9+
/// Reference to the Document Id
10+
pub id: UuidV7,
11+
/// Reference to the Document Ver, if not specified the latest document is meant
12+
pub ver: Option<UuidV7>,
2213
}
2314

2415
impl TryFrom<DocumentRef> for Value {
2516
type Error = anyhow::Error;
2617

2718
fn try_from(value: DocumentRef) -> Result<Self, Self::Error> {
28-
match value {
29-
DocumentRef::Latest { id } => encode_cbor_uuid(id),
30-
DocumentRef::WithVer { id, ver } => {
31-
Ok(Value::Array(vec![
32-
encode_cbor_uuid(id)?,
33-
encode_cbor_uuid(ver)?,
34-
]))
35-
},
19+
if let Some(ver) = value.ver {
20+
Ok(Value::Array(vec![
21+
encode_cbor_uuid(value.id)?,
22+
encode_cbor_uuid(ver)?,
23+
]))
24+
} else {
25+
encode_cbor_uuid(value.id)
3626
}
3727
}
3828
}
@@ -43,7 +33,7 @@ impl TryFrom<&Value> for DocumentRef {
4333
#[allow(clippy::indexing_slicing)]
4434
fn try_from(val: &Value) -> anyhow::Result<DocumentRef> {
4535
if let Ok(id) = decode_cbor_uuid(val.clone()) {
46-
Ok(DocumentRef::Latest { id })
36+
Ok(DocumentRef { id, ver: None })
4737
} else {
4838
let Some(array) = val.as_array() else {
4939
anyhow::bail!("Document Reference must be either a single UUID or an array of two");
@@ -58,7 +48,7 @@ impl TryFrom<&Value> for DocumentRef {
5848
ver >= id,
5949
"Document Reference Version can never be smaller than its ID"
6050
);
61-
Ok(DocumentRef::WithVer { id, ver })
51+
Ok(DocumentRef { id, ver: Some(ver) })
6252
}
6353
}
6454
}

rust/signed_doc/src/metadata/extra_fields.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,60 @@ pub struct ExtraFields {
5959
}
6060

6161
impl ExtraFields {
62+
/// Return `ref` field.
63+
#[must_use]
64+
pub fn doc_ref(&self) -> Option<DocumentRef> {
65+
self.doc_ref
66+
}
67+
68+
/// Return `template` field.
69+
#[must_use]
70+
pub fn template(&self) -> Option<DocumentRef> {
71+
self.template
72+
}
73+
74+
/// Return `reply` field.
75+
#[must_use]
76+
pub fn reply(&self) -> Option<DocumentRef> {
77+
self.reply
78+
}
79+
80+
/// Return `section` field.
81+
#[must_use]
82+
pub fn section(&self) -> Option<&String> {
83+
self.section.as_ref()
84+
}
85+
86+
/// Return `collabs` field.
87+
#[must_use]
88+
pub fn collabs(&self) -> &Vec<String> {
89+
&self.collabs
90+
}
91+
92+
/// Return `brand_id` field.
93+
#[must_use]
94+
pub fn brand_id(&self) -> Option<UuidV4> {
95+
self.brand_id
96+
}
97+
98+
/// Return `campaign_id` field.
99+
#[must_use]
100+
pub fn campaign_id(&self) -> Option<UuidV4> {
101+
self.campaign_id
102+
}
103+
104+
/// Return `election_id` field.
105+
#[must_use]
106+
pub fn election_id(&self) -> Option<UuidV4> {
107+
self.election_id
108+
}
109+
110+
/// Return `category_id` field.
111+
#[must_use]
112+
pub fn category_id(&self) -> Option<UuidV4> {
113+
self.category_id
114+
}
115+
62116
/// Fill the COSE header `ExtraFields` data into the header builder.
63117
pub(super) fn fill_cose_header_fields(
64118
&self, mut builder: coset::HeaderBuilder,

rust/signed_doc/src/metadata/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod extra_fields;
1212

1313
use algorithm::Algorithm;
1414
use anyhow::anyhow;
15-
pub use catalyst_types::uuid::{CborContext, V4 as UuidV4, V7 as UuidV7};
15+
pub use catalyst_types::uuid::{CborContext, UuidV4, UuidV7};
1616
pub use content_encoding::ContentEncoding;
1717
pub use content_type::ContentType;
1818
use coset::{iana::CoapContentFormat, CborSerializable};

0 commit comments

Comments
 (0)