Commit 9097cf39 authored by Stephane Glondu's avatar Stephane Glondu

Add Ocsipersist_ballotbox

parent 136c2fcf
open Util
module MakeBallotBox (G : Signatures.GROUP)
(U : sig val uuid : Uuidm.t end) = struct
type 'a t = 'a Lwt.t
let return = Lwt.return
let bind = Lwt.bind
let fail = Lwt.fail
let suffix = "_" ^ String.map (function
| '-' -> '_'
| c -> c
) (Uuidm.to_string U.uuid)
let ballot_table = Ocsipersist.open_table ("ballots" ^ suffix)
let record_table = Ocsipersist.open_table ("records" ^ suffix)
let prng = Lwt_preemptive.detach (fun () ->
Cryptokit.Random.(pseudo_rng (string secure_rng 16))
) ()
let random q =
let size = Z.size q * Sys.word_size / 8 in
lwt prng = prng in
let r = Cryptokit.Random.string prng size in
return Z.(of_bits r mod q)
type ballot = string
type record = string * Serializable_builtin_t.datetime
let cast b (user, date) =
Ocsipersist.add ballot_table (Common.hashB b) b >>
Ocsipersist.add record_table user date
let fold_ballots f x =
Ocsipersist.fold_step (fun k v x -> f v x) ballot_table x
let fold_records f x =
Ocsipersist.fold_step (fun k v x -> f (k, v) x) record_table x
let turnout = Ocsipersist.length ballot_table
end
(** Ocsipersist-based ballot box *)
module MakeBallotBox (G : Signatures.GROUP)
(U : sig val uuid : Uuidm.t end) : sig
(** {2 Monadic definitions} *)
include Signatures.MONAD with type 'a t = 'a Lwt.t
(** {2 Random number generation} *)
val random : Z.t -> Z.t t
(** [random q] returns a random number modulo [q]. It uses a secure
random number generator initialized by a 128-bit seed. *)
(** {2 Ballot box management} *)
include Signatures.BALLOT_BOX
with type 'a m := 'a t
and type ballot = string
and type record = string * Serializable_builtin_t.datetime
end
(** This ballot box stores ballots and records in Ocsipersist tables. *)
......@@ -5,4 +5,5 @@ Common
Election
Services
Templates
Ocsipersist_ballotbox
Registration
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