Commit 24b229ee authored by Stephane Glondu's avatar Stephane Glondu

Add voters

parent 759e873d
......@@ -49,8 +49,18 @@ let load_elections_and_votes dirname =
)
) else Lwt_stream.from_direct (fun () -> None)
in
let voters =
let file = data "voters.json" in
if Sys.file_exists file then (
Lwt_io.lines_of_file file |>
Lwt_stream.map (fun x ->
let v = Helios_datatypes_j.voter_of_string x in
v
)
) else Lwt_stream.from_direct (fun () -> None)
in
let election_data = { raw; fingerprint; election; public_data } in
Lwt.return (Some (election_data, votes))
Lwt.return (Some (election_data, votes, voters))
| None -> assert false
) else Lwt.return None
)
......@@ -84,3 +94,7 @@ let hash_vote v =
"#" ^ v.election_hash ^
"#" ^ (Uuidm.to_string v.election_uuid) |>
hashB
let hash_user v =
Helios_datatypes_j.string_of_user v |>
hashB
......@@ -8,6 +8,7 @@ type election_data = {
}
val load_elections_and_votes :
string -> (election_data * Z.t vote Lwt_stream.t) Lwt_stream.t
string -> (election_data * Z.t vote Lwt_stream.t * voter Lwt_stream.t) Lwt_stream.t
val hash_vote : Z.t vote -> string
val hash_user : user -> string
......@@ -140,6 +140,11 @@ type randomness = {
randomness : string;
}
type voter = {
user : user;
?hash : string option;
} <ocaml field_prefix="voter_">
(** {1 Compound datastructures} *)
type 'a result = {
......
......@@ -25,16 +25,21 @@ let () =
Ocsigen_messages.debug
(fun () -> "Loading elections from " ^ dir ^ "...");
Common.load_elections_and_votes dir |>
Lwt_stream.iter_s (fun (e, votes) ->
Lwt_stream.iter_s (fun (e, votes, voters) ->
let uuid = Uuidm.to_string e.Common.election.e_uuid in
Ocsigen_messages.debug
(fun () -> Printf.sprintf "-- loading %s (%s)" uuid e.Common.election.e_short_name);
lwt () = Ocsipersist.add elections_table uuid e in
let uuid_underscored = String.map (function '-' -> '_' | c -> c) uuid in
let table = Ocsipersist.open_table ("votes_" ^ uuid_underscored) in
Lwt_stream.iter_s (fun v ->
let voters_table = Ocsipersist.open_table ("voters_" ^ uuid_underscored) in
lwt () = Lwt_stream.iter_s (fun v ->
Ocsipersist.add table (Common.hash_vote v) v
) votes
) votes in
lwt () = Lwt_stream.iter_s (fun v ->
Ocsipersist.add voters_table (Common.hash_user v.voter_user) v
) voters in
return ()
) |>
Lwt_main.run
| None -> ()
......
{"user": {"name": "toto", "type": "dummy"}}
{"user": {"name": "titi", "type": "dummy"}}
......@@ -75,7 +75,7 @@ let verbose_assert msg it =
let r = Lazy.force it in
Printf.eprintf " %s\n%!" (if r then "OK" else "failed!")
let verbose_verify_election_test_data (e, votes, private_data) =
let verbose_verify_election_test_data (e, votes, voters, private_data) =
Printf.eprintf "Verifying election %S:\n%!" e.election.e_short_name;
let {g; p; q; y} = e.election.e_public_key in
let module G = (val ElGamal.make_ff_msubgroup p q g : ElGamal.GROUP with type t = Z.t) in
......@@ -110,6 +110,9 @@ let verbose_verify_election_test_data (e, votes, private_data) =
verbose_assert "result" (lazy (Crypto.verify_result e.election r));
| None -> Printf.eprintf " no results available\n%!"
);
verbose_assert "voter count" (lazy (
Array.length voters = Array.length votes
));
verbose_assert "private keys" (lazy (
Array.foralli
(fun _ k -> Crypto.verify_private_key k)
......@@ -119,10 +122,11 @@ let verbose_verify_election_test_data (e, votes, private_data) =
let load_election_and_verify_it_all dirname =
load_elections_and_votes dirname |>
Lwt_stream.to_list |> Lwt_main.run |>
List.map (fun (e, v) ->
List.map (fun (e, v, voters) ->
let votes = Lwt_stream.to_list v |> Lwt_main.run |> Array.of_list in
let voters = Lwt_stream.to_list voters |> Lwt_main.run |> Array.of_list in
let private_data = load_election_private_data dirname (Uuidm.to_string e.election.e_uuid) in
(e, votes, private_data)
(e, votes, voters, private_data)
) |>
List.iter verbose_verify_election_test_data;;
......
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