Commit cad131a8 authored by Stephane Glondu's avatar Stephane Glondu

Remove references to elections from Group

Move election_params_of_string to Election, and decompose it into two
functions.
parent e7d62bed
......@@ -351,7 +351,7 @@ let loadElection () =
setDisplayById "election_loader" "none";
setDisplayById "booth_div" "block";
let election_raw = getTextarea "election_params" |> drop_trailing_newline in
let election_params = Group.election_params_of_string election_raw in
let election_params = Election.(get_group (of_string election_raw)) in
let module P = (val election_params : ELECTION_DATA) in
let params = P.election.e_params in
setNodeById "election_name" params.e_name;
......
......@@ -20,10 +20,29 @@
(**************************************************************************)
open Platform
open Serializable_t
open Serializable_j
open Signatures
open Common
(** Parsing helpers *)
let of_string x =
let params = params_of_string Yojson.Safe.read_json x in
{
e_params = params;
e_fingerprint = sha256_b64 x;
}
let get_group x =
let w = Yojson.Safe.to_string x.e_params.e_public_key in
let module W = (val Group.wrapped_pubkey_of_string w) in
let module X =
struct
module G = W.G
let election = {x with e_params = {x.e_params with e_public_key = W.y}}
end
in (module X : ELECTION_DATA)
(** Helper functions *)
let check_modulo p x = Z.(geq x zero && lt x p)
......
......@@ -24,6 +24,9 @@
open Serializable_t
open Signatures
val of_string : string -> Yojson.Safe.json election
val get_group : Yojson.Safe.json election -> (module ELECTION_DATA)
val question_length : question -> int
module MakeElection (G : GROUP) (M : RANDOM) :
......
......@@ -19,7 +19,6 @@
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Platform
open Serializable_j
open Signatures
......@@ -37,14 +36,13 @@ let read state buf =
let module G = (val Group_field.make group : Group_field.GROUP) in
(module G : GROUP)
let election_params_of_string x =
let params = params_of_string (read_wrapped_pubkey read_ff_params read_number) x in
let {wpk_group=group; wpk_y=y} = params.e_public_key in
let module X = struct
module G = (val Group_field.make group : Group_field.GROUP)
let election = {
e_params = {params with e_public_key = y};
e_fingerprint = sha256_b64 x;
}
end in
(module X : ELECTION_DATA)
let wrapped_pubkey_of_string x =
let x = wrapped_pubkey_of_string read Yojson.Safe.read_json x in
let {wpk_group=group; wpk_y=y} = x in
let module X =
struct
module G = (val group)
let y = G.of_string (Yojson.Safe.Util.to_string y)
end
in
(module X : WRAPPED_PUBKEY)
......@@ -28,5 +28,4 @@ val of_string : string -> (module GROUP)
val read : (module GROUP) reader
val election_params_of_string : string -> (module ELECTION_DATA)
(** Parse a [Serializable_t.params]. *)
val wrapped_pubkey_of_string : string -> (module WRAPPED_PUBKEY)
......@@ -89,6 +89,12 @@ module type GROUP = sig
end
(** A public key with its group *)
module type WRAPPED_PUBKEY = sig
module G : GROUP
val y : G.t
end
(** Monad signature. *)
module type MONAD = sig
type 'a t
......
......@@ -49,7 +49,7 @@ end
let parse_params p =
let module P = (val p : PARAMS) in
let params = Group.election_params_of_string P.election in
let params = Election.(get_group (of_string P.election)) in
let module R = struct
include P
include (val params : ELECTION_DATA)
......
......@@ -66,7 +66,7 @@ let basic_check_private_key s =
let compute_partial_decryption _ =
Js.Opt.option !election >>= fun e ->
let election = Group.election_params_of_string e in
let election = Election.(get_group (of_string e)) in
let module P = (val election) in
let module E = Election.MakeElection (P.G) (DirectRandom) in
Js.Opt.option !encrypted_tally >>= fun e ->
......
......@@ -111,7 +111,7 @@ let verifydiff dir1 dir2 =
if t2 <> threshold then raise (VerifydiffError ThresholdMismatch)
in
(* the public keys / threshold parameters must be valid *)
let module ED = (val Group.election_params_of_string election) in
let module ED = (val Election.(get_group (of_string election))) in
let open ED in
let module E = Election.MakeElection (G) (DirectRandom) in
let y =
......
......@@ -61,7 +61,7 @@ let raw_find_election uuid =
let%lwt raw_election = Web_persist.get_raw_election uuid in
match raw_election with
| Some raw_election ->
return (Group.election_params_of_string raw_election)
return Election.(get_group (of_string raw_election))
| _ -> Lwt.fail Not_found
module WCacheTypes = struct
......@@ -186,7 +186,7 @@ let finalize_election uuid se =
create_file "metadata.json" string_of_metadata [metadata] >>
create_file "election.json" (fun x -> x) [raw_election] >>
(* construct Web_election instance *)
let election = Group.election_params_of_string raw_election in
let election = Election.(get_group (of_string raw_election)) in
let module W = Web_election.Make ((val election)) (LwtRandom) in
(* set up authentication *)
let%lwt () =
......
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