@@ -37,8 +37,34 @@ impl Decode<'_, ()> for Choices {
3737 d : & mut Decoder < ' _ > ,
3838 ctx : & mut ( ) ,
3939 ) -> Result < Self , minicbor:: decode:: Error > {
40- // TODO: FIXME:
41- todo ! ( )
40+ let len = decode_array_len ( d, "choices" ) ?;
41+ if len < 2 {
42+ return Err ( minicbor:: decode:: Error :: message ( format ! (
43+ "Unexpected choices array length {len}, expected at least 2"
44+ ) ) ) ;
45+ }
46+ match u8:: decode ( d, ctx) ? {
47+ 0 => Ok ( Self :: Clear ( <Vec < i64 > >:: decode ( d, ctx) ?) ) ,
48+ 1 => {
49+ let len = decode_array_len ( d, "elgamal-ristretto255-encrypted-choices" ) ?;
50+ if len < 1 || len > 2 {
51+ return Err ( minicbor:: decode:: Error :: message ( format ! (
52+ "Unexpected elgamal-ristretto255-encrypted-choices array length {len}, expected 1 or 2"
53+ ) ) ) ;
54+ }
55+ let choices = <Vec < ElgamalRistretto255Choice > >:: decode ( d, ctx) ?;
56+ let mut row_proof = None ;
57+ if len == 2 {
58+ row_proof = Some ( RowProof :: decode ( d, ctx) ?) ;
59+ }
60+ Ok ( Self :: ElgamalRistretto255 { choices, row_proof } )
61+ } ,
62+ val => {
63+ Err ( minicbor:: decode:: Error :: message ( format ! (
64+ "Unexpected choices value: {val}"
65+ ) ) )
66+ } ,
67+ }
4268 }
4369}
4470
@@ -75,10 +101,10 @@ impl Decode<'_, ()> for ElgamalRistretto255Choice {
75101 d : & mut Decoder < ' _ > ,
76102 ctx : & mut ( ) ,
77103 ) -> Result < Self , minicbor:: decode:: Error > {
78- let len = decode_array_len ( d, "encrypted choices " ) ?;
104+ let len = decode_array_len ( d, "elgamal ristretto255 choice " ) ?;
79105 if len != 2 {
80106 return Err ( minicbor:: decode:: Error :: message ( format ! (
81- "Unexpected encrypted choices array length: {len}, expected 2"
107+ "Unexpected elgamal ristretto255 choice array length: {len}, expected 2"
82108 ) ) ) ;
83109 }
84110 let c1 = <[ u8 ; 32 ] >:: decode ( d, ctx) ?;
0 commit comments