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
895d8bab
Commit
895d8bab
authored
Jun 20, 2013
by
Stephane Glondu
Browse files
Move SHA256 wrappers to Util
parent
92bf479f
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/bin/trustee-keygen.ml
View file @
895d8bab
open
Util
open
Serializable_t
let
hash
x
=
Cryptokit
.(
x
|>
hash_string
(
Hash
.
sha256
()
)
|>
transform_string
(
Hexa
.
encode
()
)
);;
(* Setup group *)
let
g
=
Z
.
of_string
"14887492224963187634282421537186040801304008017743492304481737382571933937568724473847106029915040150784031882206090286938661464458896494215273989547889201144857352611058572236578734319505128042602372864570426550855201448111746579871811249114781674309062693442442368697449970648232621880001709535143047913661432883287150003429802392229361583608686643243349727791976247247948618930423866180410558458272606627111270040091203073580238905303994472202930783207472394578498507764703191288249547659899997131166130259700604433891232298182348403175947450284433411265966789131024573629546048637848902243503970966798589660808533"
;;
...
...
@@ -28,7 +23,7 @@ assert (KG.check public_key);;
(* Save to file *)
let
id
=
String
.
sub
(
ha
sh
(
Z
.
to_string
public_key
.
trustee_public_key
))
(
s
ha
256_hex
(
Z
.
to_string
public_key
.
trustee_public_key
))
0
8
|>
String
.
uppercase
;;
...
...
src/lib/util.ml
View file @
895d8bab
...
...
@@ -116,3 +116,13 @@ let rec list_join sep = function
|
[]
->
[]
|
[
x
]
->
[
x
]
|
x
::
xs
->
x
::
sep
::
list_join
sep
xs
let
sha256_hex
x
=
Cryptokit
.(
x
|>
hash_string
(
Hash
.
sha256
()
)
|>
transform_string
(
Hexa
.
encode
()
)
)
let
sha256_b64
x
=
Cryptokit
.(
x
|>
hash_string
(
Hash
.
sha256
()
)
|>
transform_string
(
Base64
.
encode_compact
()
)
)
src/lib/util.mli
View file @
895d8bab
...
...
@@ -28,3 +28,6 @@ module String : sig
end
val
list_join
:
'
a
->
'
a
list
->
'
a
list
val
sha256_hex
:
string
->
string
val
sha256_b64
:
string
->
string
src/web/common.ml
View file @
895d8bab
...
...
@@ -46,11 +46,6 @@ let load_from_file read fname =
close_in
i
;
result
let
hashB
x
=
Cryptokit
.(
x
|>
hash_string
(
Hash
.
sha256
()
)
|>
transform_string
(
Base64
.
encode_compact
()
)
)
let
load_elections_and_votes
dirname
=
Lwt_unix
.
files_of_directory
dirname
|>
Lwt_stream
.
filter_map_s
(
fun
x
->
...
...
@@ -84,7 +79,7 @@ let load_elections_and_votes dirname =
load_from_file
(
Serializable_j
.
read_result
Serializable_builtin_j
.
read_number
)
)
with
Sys_error
_
->
None
in
let
fingerprint
=
ha
shB
raw
in
let
fingerprint
=
s
ha
256_b64
raw
in
let
ballots
=
let
file
=
data
"ballots.json"
in
if
Sys
.
file_exists
file
then
(
...
...
src/web/common.mli
View file @
895d8bab
...
...
@@ -27,7 +27,5 @@ type election_data = {
can_admin
:
acl
;
}
val
hashB
:
string
->
string
val
load_elections_and_votes
:
string
->
(
election_data
*
(
string
*
Z
.
t
ballot
)
Lwt_stream
.
t
)
Lwt_stream
.
t
src/web/ocsipersist_ballotbox.ml
View file @
895d8bab
...
...
@@ -48,7 +48,7 @@ module MakeBallotBox (E : LWT_ELECTION) = struct
)
with
e
->
Lwt
.
fail
(
Serialization
e
)
in
if
E
.
check_ballot
ballot
then
(
Ocsipersist
.
add
ballot_table
(
Common
.
hashB
rawballot
)
rawballot
>>
Ocsipersist
.
add
ballot_table
(
sha256_b64
rawballot
)
rawballot
>>
Ocsipersist
.
add
record_table
user
date
)
else
(
Lwt
.
fail
ProofCheck
...
...
src/web/registration.ml
View file @
895d8bab
...
...
@@ -41,7 +41,7 @@ let () =
let
uuid_underscored
=
String
.
map
(
function
'
-
'
->
'
_'
|
c
->
c
)
uuid
in
let
table
=
Ocsipersist
.
open_table
(
"ballots_"
^
uuid_underscored
)
in
Lwt_stream
.
iter_s
(
fun
(
r
,
v
)
->
Ocsipersist
.
add
table
(
Common
.
hashB
r
)
v
Ocsipersist
.
add
table
(
sha256_b64
r
)
v
)
ballots
>>
Ocsipersist
.
add
imported_table
uuid
true
)
else
(
...
...
@@ -266,7 +266,7 @@ let () = Eliom_registration.Html5.register
if
Uuidm
.
equal
uuid
ballot
.
election_uuid
&&
E
.
check_ballot
ballot
then
`Valid
(
Common
.
hashB
raw_ballot
)
then
`Valid
(
sha256_b64
raw_ballot
)
else
`Invalid
with
e
->
`Malformed
e
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