Commit 76858b06 authored by Stephane Glondu's avatar Stephane Glondu

Move some functions out of sandbox

parent e1d45354
......@@ -14,3 +14,21 @@ let array_foralli f x =
if i >= 0 then f i x.(i) && loop (pred i)
else true
in loop (pred (Array.length x))
let hashB x = Cryptokit.(x |>
hash_string (Hash.sha256 ()) |>
transform_string (Base64.encode_compact ())
)
let load_from_file read fname =
let i = open_in fname in
let buf = Lexing.from_channel i in
let lex = Yojson.init_lexer ~fname () in
let result = read lex buf in
close_in i;
result
let non_empty_lines_of_file fname =
Lwt_io.lines_of_file fname |>
Lwt_stream.filter (fun s -> s <> "") |>
Lwt_stream.to_list
......@@ -3,3 +3,8 @@ 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
val hashB : string -> string
val load_from_file : (Yojson.lexer_state -> Lexing.lexbuf -> 'a) -> string -> 'a
val non_empty_lines_of_file : string -> string list Lwt.t
open StdExtra
open Helios_datatypes_t
let hashB x = Cryptokit.(x |>
hash_string (Hash.sha256 ()) |>
transform_string (Base64.encode_compact ())
)
module type TYPES = sig
type elt
type 'a t
......@@ -51,13 +46,7 @@ end
module Types : TYPES with type elt = Z.t = MakeTypes (SFiniteFieldMult)
let load typ fname =
let i = open_in fname in
let buf = Lexing.from_channel i in
let lex = Yojson.init_lexer ~fname () in
let result = Types.read typ lex buf in
close_in i;
result
let load typ fname = load_from_file (Types.read typ) fname
let save typ fname x =
let o = open_out fname in
......@@ -76,11 +65,6 @@ let load_and_check ?(verbose=false) typ fname =
Sys.remove tempfname;
thing
let non_empty_lines_of_file fname =
Lwt_io.lines_of_file fname |>
Lwt_stream.filter (fun s -> s <> "") |>
Lwt_stream.to_list |> Lwt_main.run
type 'a election_test_data = {
raw : string;
fingerprint : string;
......@@ -109,6 +93,7 @@ let load_election_test_data ?(verbose=false) dir =
let fingerprint = hashB raw in
let votes =
non_empty_lines_of_file (data "votes.json") |>
Lwt_main.run |>
List.map (Helios_datatypes_j.vote_of_string Core_datatypes_j.read_number) |>
Array.of_list
in
......
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