11//! Catalyst Signed Document Extra Fields.
22
33use anyhow:: bail;
4- use catalyst_types:: problem_report:: ProblemReport ;
4+ use catalyst_types:: { problem_report:: ProblemReport , uuid :: UuidV4 } ;
55use coset:: { cbor:: Value , Label , ProtectedHeader } ;
66
7- use super :: { cose_protected_header_find, decode_cbor_uuid, encode_cbor_uuid, DocumentRef , UuidV4 } ;
7+ use super :: { cose_protected_header_find, decode_cbor_uuid, encode_cbor_uuid, DocumentRef } ;
88
99/// `ref` field COSE key value
1010const REF_KEY : & str = "ref" ;
@@ -47,16 +47,16 @@ pub struct ExtraFields {
4747 collabs : Vec < String > ,
4848 /// Unique identifier for the brand that is running the voting.
4949 #[ serde( skip_serializing_if = "Option::is_none" ) ]
50- brand_id : Option < UuidV4 > ,
50+ brand_id : Option < DocumentRef > ,
5151 /// Unique identifier for the campaign of voting.
5252 #[ serde( skip_serializing_if = "Option::is_none" ) ]
53- campaign_id : Option < UuidV4 > ,
53+ campaign_id : Option < DocumentRef > ,
5454 /// Unique identifier for the election.
5555 #[ serde( skip_serializing_if = "Option::is_none" ) ]
5656 election_id : Option < UuidV4 > ,
5757 /// Unique identifier for the voting category as a collection of proposals.
5858 #[ serde( skip_serializing_if = "Option::is_none" ) ]
59- category_id : Option < UuidV4 > ,
59+ category_id : Option < DocumentRef > ,
6060}
6161
6262impl ExtraFields {
@@ -92,13 +92,13 @@ impl ExtraFields {
9292
9393 /// Return `brand_id` field.
9494 #[ must_use]
95- pub fn brand_id ( & self ) -> Option < UuidV4 > {
95+ pub fn brand_id ( & self ) -> Option < DocumentRef > {
9696 self . brand_id
9797 }
9898
9999 /// Return `campaign_id` field.
100100 #[ must_use]
101- pub fn campaign_id ( & self ) -> Option < UuidV4 > {
101+ pub fn campaign_id ( & self ) -> Option < DocumentRef > {
102102 self . campaign_id
103103 }
104104
@@ -110,7 +110,7 @@ impl ExtraFields {
110110
111111 /// Return `category_id` field.
112112 #[ must_use]
113- pub fn category_id ( & self ) -> Option < UuidV4 > {
113+ pub fn category_id ( & self ) -> Option < DocumentRef > {
114114 self . category_id
115115 }
116116
@@ -139,12 +139,12 @@ impl ExtraFields {
139139 ) ;
140140 }
141141 if let Some ( brand_id) = & self . brand_id {
142- builder = builder. text_value ( BRAND_ID_KEY . to_string ( ) , encode_cbor_uuid ( brand_id) ?) ;
142+ builder = builder. text_value ( BRAND_ID_KEY . to_string ( ) , Value :: try_from ( * brand_id) ?) ;
143143 }
144144
145145 if let Some ( campaign_id) = & self . campaign_id {
146146 builder =
147- builder. text_value ( CAMPAIGN_ID_KEY . to_string ( ) , encode_cbor_uuid ( campaign_id) ?) ;
147+ builder. text_value ( CAMPAIGN_ID_KEY . to_string ( ) , Value :: try_from ( * campaign_id) ?) ;
148148 }
149149
150150 if let Some ( election_id) = & self . election_id {
@@ -154,7 +154,7 @@ impl ExtraFields {
154154
155155 if let Some ( category_id) = & self . category_id {
156156 builder =
157- builder. text_value ( CATEGORY_ID_KEY . to_string ( ) , encode_cbor_uuid ( * category_id) ?) ;
157+ builder. text_value ( CATEGORY_ID_KEY . to_string ( ) , Value :: try_from ( * category_id) ?) ;
158158 }
159159 Ok ( builder)
160160 }
@@ -278,7 +278,7 @@ impl ExtraFields {
278278 if let Some ( cbor_doc_brand_id) = cose_protected_header_find ( protected, |key| {
279279 key == & Label :: Text ( BRAND_ID_KEY . to_string ( ) )
280280 } ) {
281- match decode_cbor_uuid ( cbor_doc_brand_id. clone ( ) ) {
281+ match DocumentRef :: try_from ( cbor_doc_brand_id) {
282282 Ok ( brand_id) => {
283283 extra. brand_id = Some ( brand_id) ;
284284 } ,
@@ -296,7 +296,7 @@ impl ExtraFields {
296296 if let Some ( cbor_doc_campaign_id) = cose_protected_header_find ( protected, |key| {
297297 key == & Label :: Text ( CAMPAIGN_ID_KEY . to_string ( ) )
298298 } ) {
299- match decode_cbor_uuid ( cbor_doc_campaign_id. clone ( ) ) {
299+ match DocumentRef :: try_from ( cbor_doc_campaign_id) {
300300 Ok ( campaign_id) => {
301301 extra. campaign_id = Some ( campaign_id) ;
302302 } ,
@@ -332,7 +332,7 @@ impl ExtraFields {
332332 if let Some ( cbor_doc_category_id) = cose_protected_header_find ( protected, |key| {
333333 key == & Label :: Text ( CATEGORY_ID_KEY . to_string ( ) )
334334 } ) {
335- match decode_cbor_uuid ( cbor_doc_category_id. clone ( ) ) {
335+ match DocumentRef :: try_from ( cbor_doc_category_id) {
336336 Ok ( category_id) => {
337337 extra. category_id = Some ( category_id) ;
338338 } ,
0 commit comments