Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
belenios
belenios
Commits
76858b06
Commit
76858b06
authored
Jan 10, 2013
by
Stephane Glondu
Browse files
Move some functions out of sandbox
parent
e1d45354
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/stdExtra.ml
View file @
76858b06
...
...
@@ -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
src/stdExtra.mli
View file @
76858b06
...
...
@@ -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
tests/sandbox.ml
View file @
76858b06
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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment