Commit 60557d25 authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Change syntax of "belenios-tool election"

 - make "decrypt" a subcommand instead of an option
 - show help when called with no argument
 - split default action into "verify" and "finalize" subcommands
parent 37ce94b1
......@@ -37,7 +37,7 @@ If you put these files in a directory `/path/to/election`, the following
command will perform all possible verifications, depending on existing
files:
belenios-tool election --dir /path/to/election
belenios-tool election --dir /path/to/election verify
For example, during the election, you can check if some candidate
ballot is acceptable by putting it alone in `ballots.jsons`, and
......@@ -63,7 +63,7 @@ with extreme care.
To compute your decryption share, set `/path/to/election` up as
described in the _Voter's guide_ section above, and run:
belenios-tool election --dir /path/to/election --decrypt /path/to/privkey > partial_decryption.json
belenios-tool election --dir /path/to/election --privkey /path/to/privkey decrypt > partial_decryption.json
and send `partial_decryption.json` to the election
administrator.
......@@ -240,7 +240,7 @@ In the following, we assume `ocsigenserver` is properly configured.
2. Concatenate the `partial_decryption.json` received from each
trustee into a `partial_decryptions.jsons`, in the same order as in
`public_keys.jsons`.
3. Run `belenios-tool election`. It will create
3. Run `belenios-tool election finalize`. It will create
`result.json`. Publish this file, along with the files listed in
the first step above. The whole set will enable universal
verifiability.
......
......@@ -52,7 +52,9 @@ let save_to filename writer x =
module type PARAMS = sig
val sk_file : string option ref
val sk_file : string option
val do_finalize : bool
val do_decrypt : bool
val params : ff_pubkey params
val election_fingerprint : string
val group : ff_params
......@@ -66,21 +68,40 @@ module GetParams (X : sig end) : PARAMS = struct
let dir = ref (Sys.getcwd ())
let sk_file = ref None
let do_finalize = ref false
let do_decrypt = ref false
let speclist = Arg.([
"--dir", String (fun s -> dir := s), "chdir to that directory first";
"--decrypt", String (fun s -> sk_file := Some s), "do partial decryption";
"--dir", String (fun s -> dir := s), "path to election files";
"--privkey", String (fun s -> sk_file := Some s), "path to private key";
])
let usage_msg =
Printf.sprintf "Usage: %s election [--dir <dir>] [--decrypt <privkey>]" Sys.argv.(0)
Printf.sprintf "Usage: %s election [--dir <dir>] [--privkey <privkey>] { verify | decrypt | finalize }" Sys.argv.(0)
let anon_fun x =
Printf.eprintf "I do not know what to do with %s!\n" x;
let usage () =
Arg.usage speclist usage_msg;
exit 1
let anon_args = ref []
let anon_fun x =
anon_args := x :: !anon_args
let () = Arg.parse speclist anon_fun usage_msg
let () = match List.rev !anon_args with
| [] -> usage ()
| ["verify"] -> ()
| ["finalize"] -> do_finalize := true
| ["decrypt"] ->
(match !sk_file with
| None ->
Printf.eprintf "--privkey is missing\n";
exit 1
| Some _ -> do_decrypt := true)
| x :: _ -> usage ()
let () = Sys.chdir !dir
(* Load and check election *)
......@@ -97,6 +118,10 @@ module GetParams (X : sig end) : PARAMS = struct
let group = {g; p; q}
let () = assert (Election.check_finite_field group)
let sk_file = !sk_file
let do_finalize = !do_finalize
let do_decrypt = !do_decrypt
end
......@@ -190,8 +215,8 @@ module RunTool (G : Election.FF_GROUP) (P : PARAMS) = struct
) (E.neutral_ciphertext e) ()
)
let () =
match !sk_file with
let () = if do_decrypt then
match sk_file with
| Some fn ->
(match load_from_file (Serializable_builtin_j.number_of_string) fn with
| Some [sk] ->
......@@ -236,10 +261,12 @@ module RunTool (G : Election.FF_GROUP) (P : PARAMS) = struct
assert (Array.forall2 (E.check_factor tally) pks factors);
let result = E.combine_factors (M.turnout ()) tally factors in
assert (E.check_result e result);
save_to "result.json" (
Serializable_j.write_result Serializable_builtin_j.write_number
) result;
Printf.eprintf "result.json written\n%!"
if do_finalize then (
save_to "result.json" (
Serializable_j.write_result Serializable_builtin_j.write_number
) result;
Printf.eprintf "result.json written\n%!"
);
| None -> ()
(* The end *)
......
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