Commit 49b40d20 authored by Stephane Glondu's avatar Stephane Glondu

Move some StdExtra functions to overrides of stdlib

parent 326d6f01
open StdExtra
open Helios_datatypes_t
open Eliom_content.Html5.F
......@@ -230,12 +231,6 @@ let dummy_login ~service =
~header:[h2 [pcdata title]]
~content:[div [form]]
let list_iteri f xs =
let rec loop i = function
| [] -> []
| x :: xs -> f i x :: loop (succ i) xs
in List.flatten (loop 0 xs)
let election_view ~election =
let content = [
div ~a:[a_style "float: left; margin-right: 50px;"] [pcdata "FIXME"];
......@@ -274,7 +269,7 @@ let election_view ~election =
br ();
h3 ~a:[a_class ["highlight-box"]] [pcdata "Tally"];
] @ (
list_iteri (fun i question ->
List.iteri (fun i question ->
[
b [
span ~a:[a_style "font-size:0.8em;"] [
......
......@@ -141,7 +141,7 @@ module Make (G : GROUP) = struct
let verify_vote e fingerprint v =
v.election_hash = fingerprint &&
e.e_uuid = v.election_uuid &&
array_forall2 (verify_answer e.e_public_key.y) e.e_questions v.answers
Array.forall2 (verify_answer e.e_public_key.y) e.e_questions v.answers
let verify_equality h g' h' proof =
(* NB: similar to disjunctive, but with different challenge
......@@ -156,9 +156,9 @@ module Make (G : GROUP) = struct
let verify_partial_decryption election tally tpk pds =
let y = tpk.trustee_public_key.y in
let {decryption_factors = dfs; decryption_proofs = dps} = pds in
array_foralli (fun i question ->
Array.foralli (fun i question ->
let dfs_i = dfs.(i) and dps_i = dps.(i) and tally_i = tally.(i) in
array_foralli (fun j answer ->
Array.foralli (fun j answer ->
verify_equality tally_i.(j).alpha y dfs_i.(j) dps_i.(j)
) question.q_answers
) election.e_questions
......@@ -167,7 +167,7 @@ module Make (G : GROUP) = struct
(* FIXME: move this match elsewhere *)
match public_data.election_result with
| Some r ->
array_forall2 (verify_partial_decryption election r.encrypted_tally.tally)
Array.forall2 (verify_partial_decryption election r.encrypted_tally.tally)
public_data.public_keys
r.partial_decryptions
| None -> false
......@@ -176,8 +176,8 @@ module Make (G : GROUP) = struct
let pds = public_data.partial_decryptions in
let tally = public_data.encrypted_tally.tally in
let result = public_data.result in
array_foralli (fun i question ->
array_foralli (fun j answer ->
Array.foralli (fun i question ->
Array.foralli (fun j answer ->
let combined_factor = Array.fold_left (fun accu f ->
accu *~ f.decryption_factors.(i).(j)
) one pds in
......
let ( |> ) x f = f x
let ( =% ) = Z.equal
let array_forall2 f a b =
let n = Array.length a in
n = Array.length b &&
(let rec check i =
if i >= 0 then f a.(i) b.(i) && check (pred i)
else true
in check (pred n))
let array_foralli f x =
let rec loop i =
if i >= 0 then f i x.(i) && loop (pred i)
else true
in loop (pred (Array.length x))
module Array = struct
include Array
let forall2 f a b =
let n = Array.length a in
n = Array.length b &&
(let rec check i =
if i >= 0 then f a.(i) b.(i) && check (pred i)
else true
in check (pred n))
let foralli f x =
let rec loop i =
if i >= 0 then f i x.(i) && loop (pred i)
else true
in loop (pred (Array.length x))
end
module List = struct
include List
let iteri f xs =
let rec loop i = function
| [] -> []
| x :: xs -> f i x :: loop (succ i) xs
in List.flatten (loop 0 xs)
end
let hashB x = Cryptokit.(x |>
hash_string (Hash.sha256 ()) |>
......
val ( |> ) : 'a -> ('a -> 'b) -> 'b
val ( =% ) : Z.t -> Z.t -> bool
val array_forall2 : ('a -> 'b -> bool) -> 'a array -> 'b array -> bool
val array_foralli : (int -> 'a -> bool) -> 'a array -> bool
module List : sig
include module type of List
val iteri : (int -> 'a -> 'b list) -> 'a list -> 'b list
end
module Array : sig
include module type of Array
val forall2 : ('a -> 'b -> bool) -> 'a array -> 'b array -> bool
val foralli : (int -> 'a -> bool) -> 'a array -> bool
end
val hashB : string -> string
......
......@@ -119,7 +119,7 @@ let verbose_verify_election_test_data e =
e.election.e_public_key.y
e.public_data.public_keys));
verbose_assert "votes"
(lazy (array_foralli
(lazy (Array.foralli
(fun _ x -> Crypto.verify_vote e.election e.fingerprint x)
e.votes));
verbose_assert "encrypted tally"
......@@ -130,7 +130,7 @@ let verbose_verify_election_test_data e =
verbose_assert "result"
(lazy (Crypto.verify_result e.election r));
verbose_assert "private keys"
(lazy (array_foralli
(lazy (Array.foralli
(fun _ k -> Crypto.verify_private_key k)
e.private_data.private_keys));;
......
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