File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -407,8 +407,7 @@ mod tests {
407407 voter_data : VoterData ( voter_data) ,
408408 } ;
409409
410- let signature = coset:: CoseSign :: default ( ) ;
411- let generalized_tx = GeneralizedTx { tx_body, signature } ;
410+ let generalized_tx = GeneralizedTx :: new ( tx_body) ;
412411
413412 let bytes = generalized_tx. to_bytes ( ) . unwrap ( ) ;
414413 let decoded = GeneralizedTx :: from_bytes ( & bytes) . unwrap ( ) ;
Original file line number Diff line number Diff line change @@ -72,6 +72,24 @@ pub struct Proof(Vec<u8>);
7272#[ derive( Debug , Clone , PartialEq , Eq ) ]
7373pub struct PropId ( Vec < u8 > ) ;
7474
75+ impl GeneralizedTx {
76+ /// Creates a new `GeneralizedTx` struct.
77+ #[ must_use]
78+ pub fn new ( tx_body : TxBody ) -> Self {
79+ let signature = coset:: CoseSignBuilder :: new ( )
80+ . protected ( Self :: cose_protected_header ( ) )
81+ . build ( ) ;
82+ Self { tx_body, signature }
83+ }
84+
85+ /// Returns the COSE protected header.
86+ fn cose_protected_header ( ) -> coset:: Header {
87+ coset:: HeaderBuilder :: new ( )
88+ . content_format ( coset:: iana:: CoapContentFormat :: Cbor )
89+ . build ( )
90+ }
91+ }
92+
7593/// Cbor encodable and decodable type trait.
7694pub trait Cbor < ' a > : Encode < ( ) > + Decode < ' a , ( ) > {
7795 /// Encodes to CBOR encoded bytes.
You can’t perform that action at this time.
0 commit comments