@@ -45,7 +45,7 @@ impl Display for CatalystSignedDocument {
4545 writeln ! ( f, "{}" , self . inner. metadata) ?;
4646 writeln ! ( f, "Payload Size: {} bytes" , self . inner. content. len( ) ) ?;
4747 writeln ! ( f, "Signature Information" ) ?;
48- if self . inner . signatures . 0 . is_empty ( ) {
48+ if self . inner . signatures . is_empty ( ) {
4949 writeln ! ( f, " This document is unsigned." ) ?;
5050 } else {
5151 for kid in & self . inner . signatures . kids ( ) {
@@ -177,7 +177,7 @@ impl Encode<()> for CatalystSignedDocument {
177177 . protected ( protected_header)
178178 . payload ( self . inner . content . bytes ( ) . to_vec ( ) ) ;
179179
180- for signature in self . signatures ( ) . signatures ( ) {
180+ for signature in self . signatures ( ) . cose_signatures ( ) {
181181 builder = builder. add_signature ( signature) ;
182182 }
183183
@@ -192,3 +192,54 @@ impl Encode<()> for CatalystSignedDocument {
192192 . map_err ( |_| minicbor:: encode:: Error :: message ( "Failed to encode to CBOR" ) )
193193 }
194194}
195+
196+ #[ cfg( test) ]
197+ mod tests {
198+ use metadata:: { ContentEncoding , ContentType } ;
199+
200+ use super :: * ;
201+
202+ #[ test]
203+ fn catalyst_signed_doc_cbor_roundtrip_test ( ) {
204+ let uuid_v7 = UuidV7 :: new ( ) ;
205+ let uuid_v4 = UuidV4 :: new ( ) ;
206+ let section = "some section" . to_string ( ) ;
207+ let collabs = vec ! [ "collab1" . to_string( ) , "collab2" . to_string( ) ] ;
208+ let content_type = ContentType :: Json ;
209+ let content_encoding = ContentEncoding :: Brotli ;
210+
211+ let metadata = serde_json:: from_value ( serde_json:: json!( {
212+ "content-type" : content_type. to_string( ) ,
213+ "content-encoding" : content_encoding. to_string( ) ,
214+ "type" : uuid_v4. to_string( ) ,
215+ "id" : uuid_v7. to_string( ) ,
216+ "ver" : uuid_v7. to_string( ) ,
217+ "ref" : { "id" : uuid_v7. to_string( ) } ,
218+ "reply" : { "id" : uuid_v7. to_string( ) , "ver" : uuid_v7. to_string( ) } ,
219+ "template" : { "id" : uuid_v7. to_string( ) } ,
220+ "section" : section,
221+ "collabs" : collabs,
222+ "campaign_id" : uuid_v4. to_string( ) ,
223+ "election_id" : uuid_v4. to_string( ) ,
224+ "brand_id" : uuid_v4. to_string( ) ,
225+ "category_id" : uuid_v4. to_string( ) ,
226+ } ) )
227+ . unwrap ( ) ;
228+ let payload = vec ! [ 1 , 2 , 4 , 5 , 6 , 7 , 8 , 9 ] ;
229+ let content = Content :: new ( payload, content_type, Some ( content_encoding) ) . unwrap ( ) ;
230+
231+ let doc = CatalystSignedDocument {
232+ inner : InnerCatalystSignedDocument {
233+ metadata,
234+ content,
235+ signatures : Signatures :: new ( ) ,
236+ }
237+ . into ( ) ,
238+ } ;
239+
240+ let mut bytes = Vec :: new ( ) ;
241+ minicbor:: encode_with ( doc, & mut bytes, & mut ( ) ) . unwrap ( ) ;
242+ let _decoded: CatalystSignedDocument =
243+ minicbor:: decode_with ( bytes. as_slice ( ) , & mut ( ) ) . unwrap ( ) ;
244+ }
245+ }
0 commit comments