Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

template.ml 2.07 KB
Newer Older
1 2 3 4 5
open Util
open Serializable_t

(* Setup group *)

Stephane Glondu's avatar
Stephane Glondu committed
6
module G = Election.DefaultGroup;;
7
assert (Election.check_finite_field G.group);;
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

module M = Election.MakeSimpleMonad(G);;

(* Setup trustees *)

module KG = Election.MakeSimpleDistKeyGen(G)(M);;

let public_keys =
  let ic = open_in "public_keys.jsons" in
  let raw_keys =
    let rec loop xs =
      match (try Some (input_line ic) with End_of_file -> None) with
      | Some x -> loop (x::xs)
      | None -> xs
    in loop []
  in
  close_in ic;
  let keys = List.map (fun x ->
    Serializable_j.trustee_public_key_of_string Serializable_builtin_j.read_number x
  ) raw_keys |> Array.of_list in
  assert (Array.forall KG.check keys);
  keys

let y = KG.combine public_keys

(* Setup election *)

35 36
let {g; p; q} = G.group

37 38 39 40
let uuid_of_string x = match Uuidm.of_string x with
  | Some y -> y
  | None -> invalid_arg "invalid UUID"

41
let params = {
42 43
  e_description = "This is a test election.";
  e_name = "Test election";
44
  e_public_key = {ffpk_g = g; ffpk_p = p; ffpk_q = q; ffpk_y = y};
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
  e_questions =
    [|
      {
        q_answers = [| "a"; "b"; "c"; "d"; "e" |];
        q_min = 0;
        q_max = 1;
        q_question = "Question 1?";
      };
      {
        q_answers = [| "a"; "b"; "c"; "d"; "e"; "f" |];
        q_min = 2;
        q_max = 3;
        q_question = "Question 2?";
      };
      {
        q_answers = [| "a"; "b"; "c" |];
        q_min = 1;
        q_max = 1;
        q_question = "Question 3?";
      };
    |];
66
  e_uuid = uuid_of_string "00000000-0000-0000-0000-000000000000";
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
  e_short_name = "test";
};;

let metadata =
  let open CalendarLib.Fcalendar.Precise in
  let now = now () in
  {
    e_voting_starts_at = now, None;
    e_voting_ends_at = now, None;
    e_voters_list = None;
  }
;;

(* Save to disk *)

let save_to filename writer x =
  let oc = open_out filename in
  let ob = Bi_outbuf.create_channel_writer oc in
  writer ob x;
  Bi_outbuf.flush_channel_writer ob;
  close_out oc;;

open Serializable_j;;
90
save_to "election.json" (write_params write_ff_pubkey) params;;
91
save_to "metadata.json" write_metadata metadata;;