Commit f45ba5fd authored by Stephane Glondu's avatar Stephane Glondu
Browse files

Bindings for Tool_election

parent 34e8c56f
......@@ -38,6 +38,45 @@
</div>
<div id="election">
<h2>Election management</h2>
<div>
<h3>Election parameters</h3>
<textarea id="election_params" rows="1" cols="80"></textarea>
</div>
<div>
<h3>Trustee public keys</h3>
<textarea id="election_pks" rows="1" cols="80"></textarea>
</div>
<div>
<h3>Public credentials</h3>
<textarea id="election_pubcreds" rows="1" cols="80"></textarea>
</div>
<div>
<h3>Ballot creation</h3>
Secret credential:
<div><textarea id="election_privcred" rows="1" cols="80"></textarea></div>
Plaintext choices:
<div><textarea id="election_choices" rows="1" cols="80"></textarea></div>
<button id="do_encrypt">Create encrypted ballot</button>
<div><textarea id="election_ballot" rows="1" cols="80" readonly="readonly"></textarea></div>
</div>
<div>
<h3>Ballots</h3>
<textarea id="election_ballots" rows="1" cols="80"></textarea>
</div>
<div>
<h3>Partial decryption</h3>
Private key:
<div><textarea id="election_privkey" rows="1" cols="80"></textarea></div>
<button id="do_decrypt">Perform partial decryption</button>
<div><textarea id="election_pd" rows="1" cols="80" readonly="readonly"></textarea></div>
</div>
<div>
<h3>Election result</h3>
<div><textarea id="election_factors" rows="1" cols="80"></textarea></div>
<div><button id="do_finalize" rows="1" cols="80">Finalize</textarea></div>
<div><textarea id="election_result" rows="1" cols="80"></textarea></div>
<div><button id="do_verify">Verify</button></div>
</div>
</div>
<div id="credgen">
<h2>Credential management</h2>
......
......@@ -20,6 +20,7 @@
(**************************************************************************)
open Platform
open Serializable_j
let document = Dom_html.window##document
......@@ -201,7 +202,96 @@ module Mkelection = struct
]
end
let cmds = Tests.cmds @ Tkeygen.cmds @ Credgen.cmds @ Mkelection.cmds
module ToolElection = struct
open Tool_election
module Getters = struct
let get_public_keys () =
let raw = get_textarea "election_pks" |> split_lines in
let pks = Array.of_list raw in
if Array.length pks = 0 then None else Some pks
let get_public_creds () =
let raw = get_textarea "election_pubcreds" |> split_lines in
match raw with
| [] -> None
| _ -> Some (Stream.of_list raw)
let get_ballots () =
let raw = get_textarea "election_ballots" |> split_lines in
match raw with
| [] -> None
| _ -> Some (Stream.of_list raw)
let get_result () =
let raw = get_textarea "election_result" |> split_lines in
match raw with
| [] -> None
| [r] -> Some r
| _ -> invalid_arg "invalid result"
let print_msg x = alert x
end
let get_election () =
let raw = get_textarea "election_params" in
match split_lines raw with
| [e] -> e
| _ -> invalid_arg "invalid election parameters"
let create_ballot () =
let module P : PARAMS = struct
let election = get_election ()
include Getters
end in
let choices = get_textarea "election_choices" |> plaintext_of_string in
let privcred = get_textarea "election_privcred" in
let module X = (val make (module P : PARAMS) : S) in
set_textarea "election_ballot" (X.vote (Some privcred) choices)
let verify () =
let module P : PARAMS = struct
let election = get_election ()
include Getters
end in
let module X = (val make (module P : PARAMS) : S) in
X.verify ()
let decrypt () =
let module P : PARAMS = struct
let election = get_election ()
include Getters
end in
let module X = (val make (module P : PARAMS) : S) in
let privkey = get_textarea "election_privkey" in
set_textarea "election_pd" (X.decrypt privkey)
let finalize () =
let module P : PARAMS = struct
let election = get_election ()
include Getters
end in
let module X = (val make (module P : PARAMS) : S) in
let factors = get_textarea "election_factors" |> split_lines in
set_textarea "election_result" (X.finalize (Array.of_list factors))
let cmds = [
"do_encrypt", create_ballot;
"do_verify", verify;
"do_decrypt", decrypt;
"do_finalize", finalize;
]
end
let cmds =
Tests.cmds @
Tkeygen.cmds @
Credgen.cmds @
Mkelection.cmds @
ToolElection.cmds
let install_handlers () =
List.iter install_handler cmds
......
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