33use anyhow:: anyhow;
44use 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
99const 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
6161impl 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