Commit 543d87d7 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Drop {of,to}_ prefix in compat layer

parent 94163b31
open Util
open Serializable_compat_t
let of_question q =
let question q =
let {q_answers; q_min; q_max; q_question; _} = q in
let q_max = match q_max with
| Some i -> i
......@@ -10,60 +10,60 @@ let of_question q =
let open Serializable_t in
{q_answers; q_min; q_max; q_question}
let of_election e =
let election e =
let {
e_description; e_name; e_public_key;
e_questions; e_uuid; e_short_name;
_
} = e in
let e_public_key = e_public_key.y in
let e_questions = Array.map of_question e_questions in
let e_questions = Array.map question e_questions in
let open Serializable_t in
{
e_description; e_name; e_public_key;
e_questions; e_uuid; e_short_name
}
let of_proof p =
let proof p =
let {dp_challenge; dp_response; _} = p in
let open Serializable_t in
{challenge = dp_challenge; response = dp_response}
let of_proofs ps = Array.map of_proof ps
let proofs ps = Array.map proof ps
let of_answer a =
let answer a =
let {choices; individual_proofs; overall_proof} = a in
let individual_proofs = Array.map of_proofs individual_proofs in
let overall_proof = of_proofs overall_proof in
let individual_proofs = Array.map proofs individual_proofs in
let overall_proof = proofs overall_proof in
let open Serializable_t in
{choices; individual_proofs; overall_proof}
let of_ballot b =
let ballot b =
let {answers; election_hash; election_uuid} = b in
let answers = Array.map of_answer answers in
let answers = Array.map answer answers in
let open Serializable_t in
{answers; election_hash; election_uuid}
let of_partial_decryption p =
let partial_decryption p =
let {decryption_factors; decryption_proofs} = p in
let decryption_proofs = Array.mmap of_proof decryption_proofs in
let decryption_proofs = Array.mmap proof decryption_proofs in
let open Serializable_t in
{decryption_factors; decryption_proofs}
let of_result r =
let result r =
let {encrypted_tally; partial_decryptions; result} = r in
let nb_tallied = encrypted_tally.num_tallied in
let encrypted_tally = encrypted_tally.tally in
let partial_decryptions =
Array.map of_partial_decryption partial_decryptions
Array.map partial_decryption partial_decryptions
in
let open Serializable_t in
{nb_tallied; encrypted_tally; partial_decryptions; result}
module type COMPAT = sig
type t
val to_ballot : t Serializable_t.ballot -> t ballot
val to_partial_decryption : t Serializable_t.ciphertext array array ->
val ballot : t Serializable_t.ballot -> t ballot
val partial_decryption : t Serializable_t.ciphertext array array ->
t Serializable_t.partial_decryption -> t partial_decryption
end
......@@ -130,7 +130,7 @@ module MakeCompat (P : Signatures.ELECTION_PARAMS) = struct
done;
result
let to_answer a q =
let answer a q =
let {choices; individual_proofs; overall_proof} = a in
let individual_proofs =
Array.map2 (recommit d01) individual_proofs choices
......@@ -142,13 +142,13 @@ module MakeCompat (P : Signatures.ELECTION_PARAMS) = struct
let open Serializable_compat_t in
{choices; individual_proofs; overall_proof}
let to_ballot b =
let ballot b =
let {answers; election_hash; election_uuid} = b in
let answers = Array.map2 to_answer answers params.e_questions in
let answers = Array.map2 answer answers params.e_questions in
let open Serializable_compat_t in
{answers; election_hash; election_uuid}
let to_partial_decryption c p =
let partial_decryption c p =
let {decryption_factors; decryption_proofs} = p in
let decryption_proofs =
Array.mmap3 (fun {alpha; _} f {challenge; response} ->
......
......@@ -2,16 +2,16 @@
open Serializable_compat_t
val of_election : 'a election -> 'a Serializable_t.election
val of_ballot : 'a ballot -> 'a Serializable_t.ballot
val of_partial_decryption :
val election : 'a election -> 'a Serializable_t.election
val ballot : 'a ballot -> 'a Serializable_t.ballot
val partial_decryption :
'a partial_decryption -> 'a Serializable_t.partial_decryption
val of_result : 'a result -> 'a Serializable_t.result
val result : 'a result -> 'a Serializable_t.result
module type COMPAT = sig
type t
val to_ballot : t Serializable_t.ballot -> t ballot
val to_partial_decryption : t Serializable_t.ciphertext array array ->
val ballot : t Serializable_t.ballot -> t ballot
val partial_decryption : t Serializable_t.ciphertext array array ->
t Serializable_t.partial_decryption -> t partial_decryption
end
......
......@@ -87,7 +87,7 @@ let verbose_verify_election_test_data (e, ballots, signatures, private_data) =
Array.map (fun x ->
x.trustee_public_key.y
) e.public_data.public_keys
let params = Serializable_compat.of_election e.election
let params = Serializable_compat.election e.election
let fingerprint = e.fingerprint
end in
verbose_assert "election key" (lazy (
......@@ -100,7 +100,7 @@ let verbose_verify_election_test_data (e, ballots, signatures, private_data) =
) else (
verbose_assert "ballots" (lazy (
Array.foralli (fun _ x ->
E.check_ballot (Serializable_compat.of_ballot x)
E.check_ballot (Serializable_compat.ballot x)
) ballots
));
(*
......@@ -174,7 +174,7 @@ module P = struct
Array.map (fun x ->
x.trustee_public_key.y
) e.public_data.public_keys
let params = Serializable_compat.of_election e.election
let params = Serializable_compat.election e.election
let fingerprint = e.fingerprint
end
......@@ -182,9 +182,9 @@ module M = Election.MakeSimpleMonad(P.G)
module E = Election.MakeElection(P)(M)
module Compat = Serializable_compat.MakeCompat(P)
let nballots = Array.map Serializable_compat.of_ballot ballots;;
let nballots = Array.map Serializable_compat.ballot ballots;;
assert (Array.forall E.check_ballot nballots);;
assert (Array.forall2 (fun b b' -> b = Compat.to_ballot b') ballots nballots);;
assert (Array.forall2 (fun b b' -> b = Compat.ballot b') ballots nballots);;
let create_ballot b = E.(create_ballot (make_randomness () ()) b)
......@@ -197,8 +197,8 @@ let result =
| None -> assert false
let tally = result.encrypted_tally.tally;;
let fs = Array.map Serializable_compat.of_partial_decryption result.partial_decryptions;;
assert (Array.forall2 (fun f f' -> f = Compat.to_partial_decryption tally f') result.partial_decryptions fs);;
let fs = Array.map Serializable_compat.partial_decryption result.partial_decryptions;;
assert (Array.forall2 (fun f f' -> f = Compat.partial_decryption tally f') result.partial_decryptions fs);;
let ys = Array.map (fun x -> x.trustee_public_key.y) e.public_data.public_keys;;
assert (Array.forall2 (E.check_factor tally) ys fs);;
......@@ -210,7 +210,7 @@ let test_factor = E.compute_factor tally x ();;
assert (E.check_factor tally y test_factor);;
assert (Serializable_t.(test_factor.decryption_factors) = result.partial_decryptions.(0).decryption_factors);;
let nresult = Serializable_compat.of_result result;;
let nresult = Serializable_compat.result result;;
let () =
let open Serializable_t in
......
......@@ -189,14 +189,14 @@ let () = Eliom_registration.Html5.register
let public_keys = Array.map (fun x ->
x.trustee_public_key.y
) election.Common.public_data.public_keys
let params = Serializable_compat.of_election election.Common.election
let params = Serializable_compat.election election.Common.election
let fingerprint = assert false
end in
let module M = Election.MakeSimpleMonad(P.G) in
let module E = Election.MakeElection(P)(M) in
if
Uuidm.equal uuid ballot.election_uuid &&
E.check_ballot (Serializable_compat.of_ballot ballot)
E.check_ballot (Serializable_compat.ballot ballot)
then `Valid (Common.hash_ballot ballot)
else `Invalid
with e -> `Malformed
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment