Commit 531bbeb1 authored by Stephane Glondu's avatar Stephane Glondu

More consistent "open" directives

In each directory, always open in the following order:
 1. third-party libraries
 2. serializable
 3. signatures
 4. common

Also, always open modules from lib/* before. This order is reflected
in *.mllib files.

Additionally, open more frequently serialization modules.
parent 252c0eef
......@@ -19,9 +19,10 @@
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Serializable_builtin_j
open Serializable_j
open Signatures
open Common
open Serializable_t
(* Helpers *)
......@@ -41,8 +42,6 @@ let load_from_file of_string filename =
Some (List.rev lines)
) else None
let read_number = Serializable_builtin_j.read_number
module type PARAMS = sig
val sk_file : string option
......@@ -115,7 +114,7 @@ module GetParams (X : EMPTY) : PARAMS = struct
let params, election_fingerprint =
match (load_from_file (fun l ->
Serializable_j.(params_of_string read_ff_pubkey l),
params_of_string read_ff_pubkey l,
sha256_b64 l
) "election.json") with
| Some [e] -> e
......@@ -144,7 +143,7 @@ module RunTool (G : Group_field.GROUP) (P : PARAMS) = struct
let public_keys_with_pok =
load_from_file (
Serializable_j.trustee_public_key_of_string read_number
trustee_public_key_of_string read_number
) "public_keys.jsons" |> option_map Array.of_list
let () =
......@@ -186,7 +185,7 @@ module RunTool (G : Group_field.GROUP) (P : PARAMS) = struct
let ballots =
load_from_file (fun line ->
Serializable_j.ballot_of_string read_number line,
ballot_of_string read_number line,
sha256_b64 line
) "ballots.jsons"
......@@ -218,7 +217,7 @@ module RunTool (G : Group_field.GROUP) (P : PARAMS) = struct
let () = match ballot_file with
| None -> ()
| Some fn ->
(match load_from_file Serializable_j.plaintext_of_string fn with
(match load_from_file plaintext_of_string fn with
| Some [b] ->
let sk =
match sk_file with
......@@ -233,17 +232,14 @@ module RunTool (G : Group_field.GROUP) (P : PARAMS) = struct
in
let b = E.create_ballot e ?sk (E.make_randomness e ()) b () in
assert (E.check_ballot e b);
print_endline (
Serializable_j.string_of_ballot
Serializable_builtin_j.write_number b
)
print_endline (string_of_ballot write_number b)
| _ -> failwith "invalid plaintext ballot file"
)
let () = if do_decrypt then
match sk_file with
| Some fn ->
(match load_from_file (Serializable_builtin_j.number_of_string) fn with
(match load_from_file (number_of_string) fn with
| Some [sk] ->
let pk = G.(g **~ sk) in
if Array.forall (fun x -> not (x =% pk)) pks then (
......@@ -254,11 +250,7 @@ module RunTool (G : Group_field.GROUP) (P : PARAMS) = struct
E.compute_factor tally sk ()
in
assert (E.check_factor tally pk factor);
print_endline (
Serializable_j.string_of_partial_decryption
Serializable_builtin_j.write_number
factor
)
print_endline (string_of_partial_decryption write_number factor)
| _ -> failwith "invalid private key file"
)
| None -> ()
......@@ -267,7 +259,7 @@ module RunTool (G : Group_field.GROUP) (P : PARAMS) = struct
let result =
load_from_file (
Serializable_j.result_of_string read_number
result_of_string read_number
) "result.json"
let () =
......@@ -278,7 +270,7 @@ module RunTool (G : Group_field.GROUP) (P : PARAMS) = struct
failwith "invalid result file"
| None ->
let factors = load_from_file (
Serializable_j.partial_decryption_of_string read_number
partial_decryption_of_string read_number
) "partial_decryptions.jsons" |> option_map Array.of_list in
match factors with
| Some factors ->
......@@ -288,7 +280,7 @@ module RunTool (G : Group_field.GROUP) (P : PARAMS) = struct
assert (E.check_result e result);
if do_finalize then (
save_to "result.json" (
Serializable_j.write_result Serializable_builtin_j.write_number
write_result write_number
) result;
Printf.eprintf "result.json written\n%!"
);
......
......@@ -19,9 +19,10 @@
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Common
open Serializable_t
open Serializable_builtin_j
open Serializable_j
open Signatures
open Common
module type PARAMS = sig
val group : (module Group_field.GROUP)
......@@ -61,7 +62,7 @@ module GetParams (X : EMPTY) : PARAMS = struct
let ic = open_in fname in
let ls = Yojson.init_lexer () in
let lb = Lexing.from_channel ic in
let r = Serializable_j.read_ff_params ls lb in
let r = read_ff_params ls lb in
close_in ic;
Group_field.make r
......@@ -77,7 +78,7 @@ module GetParams (X : EMPTY) : PARAMS = struct
let ic = open_in fname in
let ls = Yojson.init_lexer () in
let lb = Lexing.from_channel ic in
let r = Serializable_j.read_template ls lb in
let r = read_template ls lb in
close_in ic;
r
end
......@@ -103,7 +104,7 @@ module MakeElection (G : Group_field.GROUP) (P : PARAMS) = struct
in
close_in ic;
let keys = List.map (fun x ->
Serializable_j.trustee_public_key_of_string Serializable_builtin_j.read_number x
trustee_public_key_of_string read_number x
) raw_keys |> Array.of_list in
assert (Array.forall KG.check keys);
keys
......@@ -125,7 +126,6 @@ module MakeElection (G : Group_field.GROUP) (P : PARAMS) = struct
(* Save to disk *)
open Serializable_j
let () = save_to "election.json" (write_params write_ff_pubkey) params
end
......
......@@ -19,9 +19,10 @@
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Common
open Serializable_t
open Serializable_builtin_j
open Serializable_j
open Signatures
open Common
module type PARAMS = sig
val group : (module Group_field.GROUP)
......@@ -55,7 +56,7 @@ module GetParams (X : EMPTY) : PARAMS = struct
let ic = open_in fname in
let ls = Yojson.init_lexer () in
let lb = Lexing.from_channel ic in
let r = Serializable_j.read_ff_params ls lb in
let r = read_ff_params ls lb in
close_in ic;
Group_field.make r
end
......@@ -86,14 +87,14 @@ module RunTrusteeKeygen (G : Group_field.GROUP) = struct
id ^ ".pubkey",
0o444,
public_key,
Serializable_j.write_trustee_public_key Serializable_builtin_j.write_number
write_trustee_public_key write_number
let privkey =
"private",
id ^ ".privkey",
0o400,
private_key,
Serializable_builtin_j.write_number
write_number
let save (kind, filename, perm, thing, writer) =
let oc = open_out_gen [Open_wronly; Open_creat] perm filename in
......
......@@ -19,9 +19,9 @@
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Common
open Serializable_t
open Signatures
open Common
(** Helper functions *)
......@@ -54,7 +54,7 @@ module MakeSimpleMonad (G : GROUP) = struct
let r = Cryptokit.Random.string (Lazy.force prng) size in
Z.(of_bits r mod q)
type elt = G.t Serializable_t.ballot
type elt = G.t ballot
let cast x () = ballots := x :: !ballots
let fold f x () = List.fold_left (fun accu b -> f () b accu ()) x !ballots
let cardinal () = List.length !ballots
......@@ -353,7 +353,7 @@ module MakeElection (G : GROUP) (M : RANDOM) = struct
let extract_ciphertext b = Array.map (fun x -> x.choices) b.answers
type factor = elt Serializable_t.partial_decryption
type factor = elt partial_decryption
let eg_factor x {alpha; beta} =
let zkp = "decrypt|" ^ G.to_string (g **~ x) ^ "|" in
......
......@@ -21,6 +21,7 @@
(** Election primitives *)
open Serializable_t
open Signatures
val check_election_public_key : (module GROUP with type t = 'a) ->
......@@ -44,7 +45,7 @@ module MakeSimpleMonad (G : GROUP) : sig
include Signatures.MONADIC_MAP_RO
with type 'a m := 'a t
and type elt = G.t Serializable_t.ballot
and type elt = G.t ballot
and type key := unit
val cast : elt -> unit t
......@@ -59,15 +60,15 @@ module MakeSimpleDistKeyGen (G : GROUP) (M : RANDOM) : sig
a distributed fashion. *)
val generate_and_prove :
unit -> (Z.t * G.t Serializable_t.trustee_public_key) M.t
unit -> (Z.t * G.t trustee_public_key) M.t
(** [generate_and_prove ()] returns a new keypair [(x, y)]. [x] is
the secret exponent, [y] contains the public key and a
zero-knowledge proof of knowledge of [x]. *)
val check : G.t Serializable_t.trustee_public_key -> bool
val check : G.t trustee_public_key -> bool
(** Check a public key and its proof. *)
val combine : G.t Serializable_t.trustee_public_key array -> G.t
val combine : G.t trustee_public_key array -> G.t
(** Combine all public key shares into an election public key. *)
end
......
......@@ -19,8 +19,8 @@
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Common
open Serializable_j
open Common
(** Helper functions *)
......
......@@ -21,15 +21,17 @@
(** Finite field arithmetic *)
open Serializable_t
module type GROUP = Signatures.GROUP
with type t = Z.t
and type group = Serializable_t.ff_params
and type group = ff_params
(** Multiplicative subgroup of a finite field. *)
val check_params : Serializable_t.ff_params -> bool
val check_params : ff_params -> bool
(** Check consistency of finite field parameters. *)
val make : Serializable_t.ff_params -> (module GROUP)
val make : ff_params -> (module GROUP)
(** [finite_field params] builds the multiplicative subgroup of
F[params.p], generated by [params.g], of order [params.q]. It
checks the consistency of the parameters. *)
Common
Serializable_builtin_j
Serializable_t
Serializable_j
Common
Group_field
Election
......@@ -21,6 +21,8 @@
(** Signatures *)
open Serializable_t
(** Empty module *)
module type EMPTY = sig end
......@@ -113,7 +115,7 @@ end
(** Parameters for an election. *)
type 'a election = {
e_params : 'a Serializable_t.params;
e_params : 'a params;
(** Parameters of the election. *)
e_pks : 'a array option;
......@@ -189,7 +191,7 @@ module type ELECTION = sig
(** {2 Partial decryptions} *)
type factor = elt Serializable_t.partial_decryption
type factor = elt partial_decryption
(** A decryption share. It is computed by a trustee from his or her
private key share and the encrypted tally, and contains a
cryptographic proof that he or she didn't cheat. *)
......
Common
Serializable_builtin_j
Serializable_j
Common
Group_field
Election
Web_serializable_j
Web_common
Web_auth
Web_election
Web_site
Web_templates
Auth_dummy
Auth_password
Auth_cas
Web_election
Group_field
Election
Web_templates
Web_site
Web_main
......@@ -20,9 +20,9 @@
(**************************************************************************)
open Lwt
open Common
open Serializable_t
open Signatures
open Common
open Web_serializable_t
open Web_signatures
open Web_common
......
......@@ -19,10 +19,10 @@
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Signatures
open Lwt
open Signatures
open Common
open Serializable_builtin_t
open Serializable_builtin_j
open Serializable_t
open Web_serializable_t
......@@ -116,10 +116,7 @@ let security_log s =
| None -> return ()
| Some ic -> Lwt_io.atomic (fun ic ->
Lwt_io.write ic (
Serializable_builtin_j.string_of_datetime (
CalendarLib.Fcalendar.Precise.now (),
None
)
string_of_datetime (CalendarLib.Fcalendar.Precise.now (), None)
) >>
Lwt_io.write ic ": " >>
Lwt_io.write_line ic (s ()) >>
......
......@@ -19,13 +19,13 @@
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Signatures
open Web_signatures
open Lwt
open Common
open Serializable_builtin_t
open Serializable_t
open Serializable_j
open Signatures
open Common
open Web_serializable_t
open Web_signatures
open Web_common
let can_read m user =
......@@ -52,9 +52,7 @@ end
let make config =
let e_fingerprint = sha256_b64 config.raw_election in
let wrapped_params = Serializable_j.params_of_string
Serializable_j.read_ff_pubkey config.raw_election
in
let wrapped_params = params_of_string read_ff_pubkey config.raw_election in
let {ffpk_g = g; ffpk_p = p; ffpk_q = q; ffpk_y = y} = wrapped_params.e_public_key in
let group = {g; p; q} in
let e_params = { wrapped_params with e_public_key = y } in
......@@ -107,7 +105,7 @@ let make config =
module Records = struct
type 'a m = 'a Lwt.t
type elt = Serializable_builtin_t.datetime * string
type elt = datetime * string
type key = string
let table = Ocsipersist.open_table ("records" ^ suffix)
let cardinal = Ocsipersist.length table
......@@ -144,10 +142,8 @@ let make config =
fail (Serialization (Invalid_argument "multiline ballot"))
) else return () >>
lwt ballot =
try Lwt.return (
Serializable_j.ballot_of_string
Serializable_builtin_j.read_number rawballot
) with e -> fail (Serialization e)
try Lwt.return (ballot_of_string read_number rawballot)
with e -> fail (Serialization e)
in
lwt credential =
match ballot.signature with
......@@ -356,9 +352,8 @@ let make config =
if W.metadata.e_owner = Some u then (
(* TODO: streaming *)
lwt ballots = W.B.Records.fold (fun u (d, _) xs ->
let x = Printf.sprintf "%s %S\n"
(Serializable_builtin_j.string_of_datetime d) u
in return (x::xs)
let x = Printf.sprintf "%s %S\n" (string_of_datetime d) u in
return (x::xs)
) [] in
let s = List.map (fun b () ->
return (Ocsigen_stream.of_string b)
......
......@@ -19,13 +19,13 @@
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Lwt
open Serializable_t
open Signatures
open Common
open Serializable_t
open Web_serializable_j
open Lwt
open Web_common
open Web_signatures
open Web_common
(** Global initialization *)
......
......@@ -21,9 +21,9 @@
open Serializable_builtin_t
open Serializable_t
open Signatures
open Common
open Web_serializable_t
open Signatures
type election_config = {
raw_election : string;
......@@ -198,7 +198,7 @@ module type WEB_BALLOT_BOX = sig
and type key = string
module Records : MONADIC_MAP_RO
with type 'a m = 'a Lwt.t
and type elt = Serializable_builtin_t.datetime * string
and type elt = datetime * string
and type key = string
val cast : string -> string * datetime -> string Lwt.t
......
......@@ -20,9 +20,9 @@
(**************************************************************************)
open Lwt
open Common
open Serializable_t
open Signatures
open Common
open Web_serializable_j
open Web_common
open Web_signatures
......
......@@ -20,9 +20,9 @@
(**************************************************************************)
open Lwt
open Serializable_t
open Signatures
open Common
open Serializable_t
open Web_serializable_t
open Web_signatures
open Web_common
......
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