Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/signed_doc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license.workspace = true
workspace = true

[dependencies]
catalyst-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250122-00" }
catalyst-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250124-00" }
anyhow = "1.0.95"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.134"
Expand Down
39 changes: 15 additions & 24 deletions rust/signed_doc/src/metadata/document_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,25 @@ use super::{decode_cbor_uuid, encode_cbor_uuid, UuidV7};

/// Reference to a Document.
#[derive(Copy, Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum DocumentRef {
/// Reference to the latest document
Latest {
/// Document ID UUID
id: UuidV7,
},
/// Reference to the specific document version
WithVer {
/// Document ID UUID,
id: UuidV7,
/// Document Ver UUID
ver: UuidV7,
},
pub struct DocumentRef {
/// Reference to the Document Id
pub id: UuidV7,
/// Reference to the Document Ver, if not specified the latest document is meant
#[serde(skip_serializing_if = "Option::is_none")]
pub ver: Option<UuidV7>,
}

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

fn try_from(value: DocumentRef) -> Result<Self, Self::Error> {
match value {
DocumentRef::Latest { id } => encode_cbor_uuid(id),
DocumentRef::WithVer { id, ver } => {
Ok(Value::Array(vec![
encode_cbor_uuid(id)?,
encode_cbor_uuid(ver)?,
]))
},
if let Some(ver) = value.ver {
Ok(Value::Array(vec![
encode_cbor_uuid(value.id)?,
encode_cbor_uuid(ver)?,
]))
} else {
encode_cbor_uuid(value.id)
}
}
}
Expand All @@ -43,7 +34,7 @@ impl TryFrom<&Value> for DocumentRef {
#[allow(clippy::indexing_slicing)]
fn try_from(val: &Value) -> anyhow::Result<DocumentRef> {
if let Ok(id) = decode_cbor_uuid(val.clone()) {
Ok(DocumentRef::Latest { id })
Ok(DocumentRef { id, ver: None })
} else {
let Some(array) = val.as_array() else {
anyhow::bail!("Document Reference must be either a single UUID or an array of two");
Expand All @@ -58,7 +49,7 @@ impl TryFrom<&Value> for DocumentRef {
ver >= id,
"Document Reference Version can never be smaller than its ID"
);
Ok(DocumentRef::WithVer { id, ver })
Ok(DocumentRef { id, ver: Some(ver) })
}
}
}
54 changes: 54 additions & 0 deletions rust/signed_doc/src/metadata/extra_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,60 @@ pub struct ExtraFields {
}

impl ExtraFields {
/// Return `ref` field.
#[must_use]
pub fn doc_ref(&self) -> Option<DocumentRef> {
self.doc_ref
}

/// Return `template` field.
#[must_use]
pub fn template(&self) -> Option<DocumentRef> {
self.template
}

/// Return `reply` field.
#[must_use]
pub fn reply(&self) -> Option<DocumentRef> {
self.reply
}

/// Return `section` field.
#[must_use]
pub fn section(&self) -> Option<&String> {
self.section.as_ref()
}

/// Return `collabs` field.
#[must_use]
pub fn collabs(&self) -> &Vec<String> {
&self.collabs
}

/// Return `brand_id` field.
#[must_use]
pub fn brand_id(&self) -> Option<UuidV4> {
self.brand_id
}

/// Return `campaign_id` field.
#[must_use]
pub fn campaign_id(&self) -> Option<UuidV4> {
self.campaign_id
}

/// Return `election_id` field.
#[must_use]
pub fn election_id(&self) -> Option<UuidV4> {
self.election_id
}

/// Return `category_id` field.
#[must_use]
pub fn category_id(&self) -> Option<UuidV4> {
self.category_id
}

/// Fill the COSE header `ExtraFields` data into the header builder.
pub(super) fn fill_cose_header_fields(
&self, mut builder: coset::HeaderBuilder,
Expand Down
2 changes: 1 addition & 1 deletion rust/signed_doc/src/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod extra_fields;

use algorithm::Algorithm;
use anyhow::anyhow;
pub use catalyst_types::uuid::{CborContext, V4 as UuidV4, V7 as UuidV7};
pub use catalyst_types::uuid::{CborContext, UuidV4, UuidV7};
pub use content_encoding::ContentEncoding;
pub use content_type::ContentType;
use coset::{iana::CoapContentFormat, CborSerializable};
Expand Down
Loading