Skip to content

Commit 578659e

Browse files
committed
update ExtraField
1 parent 7523dfa commit 578659e

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

rust/signed_doc/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ mod tests {
222222
"template": {"id": uuid_v7.to_string()},
223223
"section": section,
224224
"collabs": collabs,
225-
"campaign_id": uuid_v4.to_string(),
226-
"election_id": uuid_v4.to_string(),
227-
"brand_id": uuid_v4.to_string(),
228-
"category_id": uuid_v4.to_string(),
225+
"campaign_id": {"id": uuid_v7.to_string()},
226+
"election_id": {"id": uuid_v7.to_string()},
227+
"brand_id": {"id": uuid_v7.to_string()},
228+
"category_id": {"id": uuid_v7.to_string()},
229229
}))
230230
.unwrap();
231231
let content = vec![1, 2, 4, 5, 6, 7, 8, 9];

rust/signed_doc/src/metadata/extra_fields.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use anyhow::anyhow;
44
use coset::{cbor::Value, Label, ProtectedHeader};
55

6-
use super::{cose_protected_header_find, decode_cbor_uuid, encode_cbor_uuid, DocumentRef, UuidV4};
6+
use super::{cose_protected_header_find, DocumentRef};
77

88
/// `ref` field COSE key value
99
const REF_KEY: &str = "ref";
@@ -46,16 +46,16 @@ pub struct ExtraFields {
4646
collabs: Vec<String>,
4747
/// Unique identifier for the brand that is running the voting.
4848
#[serde(skip_serializing_if = "Option::is_none")]
49-
brand_id: Option<UuidV4>,
49+
brand_id: Option<DocumentRef>,
5050
/// Unique identifier for the campaign of voting.
5151
#[serde(skip_serializing_if = "Option::is_none")]
52-
campaign_id: Option<UuidV4>,
52+
campaign_id: Option<DocumentRef>,
5353
/// Unique identifier for the election.
5454
#[serde(skip_serializing_if = "Option::is_none")]
55-
election_id: Option<UuidV4>,
55+
election_id: Option<DocumentRef>,
5656
/// Unique identifier for the voting category as a collection of proposals.
5757
#[serde(skip_serializing_if = "Option::is_none")]
58-
category_id: Option<UuidV4>,
58+
category_id: Option<DocumentRef>,
5959
}
6060

6161
impl ExtraFields {
@@ -91,25 +91,25 @@ impl ExtraFields {
9191

9292
/// Return `brand_id` field.
9393
#[must_use]
94-
pub fn brand_id(&self) -> Option<UuidV4> {
94+
pub fn brand_id(&self) -> Option<DocumentRef> {
9595
self.brand_id
9696
}
9797

9898
/// Return `campaign_id` field.
9999
#[must_use]
100-
pub fn campaign_id(&self) -> Option<UuidV4> {
100+
pub fn campaign_id(&self) -> Option<DocumentRef> {
101101
self.campaign_id
102102
}
103103

104104
/// Return `election_id` field.
105105
#[must_use]
106-
pub fn election_id(&self) -> Option<UuidV4> {
106+
pub fn election_id(&self) -> Option<DocumentRef> {
107107
self.election_id
108108
}
109109

110110
/// Return `category_id` field.
111111
#[must_use]
112-
pub fn category_id(&self) -> Option<UuidV4> {
112+
pub fn category_id(&self) -> Option<DocumentRef> {
113113
self.category_id
114114
}
115115

@@ -138,22 +138,22 @@ impl ExtraFields {
138138
);
139139
}
140140
if let Some(brand_id) = &self.brand_id {
141-
builder = builder.text_value(BRAND_ID_KEY.to_string(), encode_cbor_uuid(brand_id)?);
141+
builder = builder.text_value(BRAND_ID_KEY.to_string(), Value::try_from(*brand_id)?);
142142
}
143143

144144
if let Some(campaign_id) = &self.campaign_id {
145145
builder =
146-
builder.text_value(CAMPAIGN_ID_KEY.to_string(), encode_cbor_uuid(campaign_id)?);
146+
builder.text_value(CAMPAIGN_ID_KEY.to_string(), Value::try_from(*campaign_id)?);
147147
}
148148

149149
if let Some(election_id) = &self.election_id {
150150
builder =
151-
builder.text_value(ELECTION_ID_KEY.to_string(), encode_cbor_uuid(election_id)?);
151+
builder.text_value(ELECTION_ID_KEY.to_string(), Value::try_from(*election_id)?);
152152
}
153153

154154
if let Some(category_id) = &self.category_id {
155155
builder =
156-
builder.text_value(CATEGORY_ID_KEY.to_string(), encode_cbor_uuid(*category_id)?);
156+
builder.text_value(CATEGORY_ID_KEY.to_string(), Value::try_from(*category_id)?);
157157
}
158158
Ok(builder)
159159
}
@@ -258,7 +258,7 @@ impl TryFrom<&ProtectedHeader> for ExtraFields {
258258
if let Some(cbor_doc_brand_id) = cose_protected_header_find(protected, |key| {
259259
key == &Label::Text(BRAND_ID_KEY.to_string())
260260
}) {
261-
match decode_cbor_uuid(cbor_doc_brand_id.clone()) {
261+
match DocumentRef::try_from(cbor_doc_brand_id) {
262262
Ok(brand_id) => {
263263
extra.brand_id = Some(brand_id);
264264
},
@@ -273,7 +273,7 @@ impl TryFrom<&ProtectedHeader> for ExtraFields {
273273
if let Some(cbor_doc_campaign_id) = cose_protected_header_find(protected, |key| {
274274
key == &Label::Text(CAMPAIGN_ID_KEY.to_string())
275275
}) {
276-
match decode_cbor_uuid(cbor_doc_campaign_id.clone()) {
276+
match DocumentRef::try_from(cbor_doc_campaign_id) {
277277
Ok(campaign_id) => {
278278
extra.campaign_id = Some(campaign_id);
279279
},
@@ -288,7 +288,7 @@ impl TryFrom<&ProtectedHeader> for ExtraFields {
288288
if let Some(cbor_doc_election_id) = cose_protected_header_find(protected, |key| {
289289
key == &Label::Text(ELECTION_ID_KEY.to_string())
290290
}) {
291-
match decode_cbor_uuid(cbor_doc_election_id.clone()) {
291+
match DocumentRef::try_from(cbor_doc_election_id) {
292292
Ok(election_id) => {
293293
extra.election_id = Some(election_id);
294294
},
@@ -303,7 +303,7 @@ impl TryFrom<&ProtectedHeader> for ExtraFields {
303303
if let Some(cbor_doc_category_id) = cose_protected_header_find(protected, |key| {
304304
key == &Label::Text(CATEGORY_ID_KEY.to_string())
305305
}) {
306-
match decode_cbor_uuid(cbor_doc_category_id.clone()) {
306+
match DocumentRef::try_from(cbor_doc_category_id) {
307307
Ok(category_id) => {
308308
extra.category_id = Some(category_id);
309309
},

0 commit comments

Comments
 (0)