Skip to content

Commit 29a3ee4

Browse files
committed
wip
1 parent 950f696 commit 29a3ee4

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

rust/vote-tx-v2/src/decoding.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff 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();

rust/vote-tx-v2/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ pub struct Proof(Vec<u8>);
7272
#[derive(Debug, Clone, PartialEq, Eq)]
7373
pub 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.
7694
pub trait Cbor<'a>: Encode<()> + Decode<'a, ()> {
7795
/// Encodes to CBOR encoded bytes.

0 commit comments

Comments
 (0)