Skip to content

Commit d45601d

Browse files
ElgamalRistretto255Choice encoding decoding
1 parent 1f73105 commit d45601d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

rust/catalyst-contest/src/choices.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Voters Choices.
22
3+
use cbork_utils::decode_helper::decode_array_len;
34
use minicbor::{Decode, Decoder, Encode, Encoder, encode::Write};
45

56
/// Voters Choices.
@@ -74,8 +75,15 @@ impl Decode<'_, ()> for ElgamalRistretto255Choice {
7475
d: &mut Decoder<'_>,
7576
ctx: &mut (),
7677
) -> Result<Self, minicbor::decode::Error> {
77-
// TODO: FIXME:
78-
todo!()
78+
let len = decode_array_len(d, "encrypted choices")?;
79+
if len != 2 {
80+
return Err(minicbor::decode::Error::message(format!(
81+
"Unexpected encrypted choices array length: {len}, expected 2"
82+
)));
83+
}
84+
let c1 = <[u8; 32]>::decode(d, ctx)?;
85+
let c2 = <[u8; 32]>::decode(d, ctx)?;
86+
Ok(ElgamalRistretto255Choice { c1, c2 })
7987
}
8088
}
8189

@@ -85,8 +93,9 @@ impl Encode<()> for ElgamalRistretto255Choice {
8593
e: &mut Encoder<W>,
8694
ctx: &mut (),
8795
) -> Result<(), minicbor::encode::Error<W::Error>> {
88-
// TODO: FIXME:
89-
todo!()
96+
e.array(2)?;
97+
self.c1.encode(e, ctx)?;
98+
self.c2.encode(e, ctx)
9099
}
91100
}
92101

0 commit comments

Comments
 (0)