Commit 850e05df authored by Stephane Glondu's avatar Stephane Glondu

Fix warnings 3 (deprecated stuff) and use safe_string

parent f623971b
...@@ -5,4 +5,4 @@ ...@@ -5,4 +5,4 @@
<src/tool/tool_js*> or <src/platform/js/*> or <src/booth/*>: package(js_of_ocaml), syntax(camlp4o), package(js_of_ocaml.syntax), package(lwt.syntax), use_platform-js <src/tool/tool_js*> or <src/platform/js/*> or <src/booth/*>: package(js_of_ocaml), syntax(camlp4o), package(js_of_ocaml.syntax), package(lwt.syntax), use_platform-js
<**/*serializable_j.ml>: warn(-32) <**/*serializable_j.ml>: warn(-32)
true: warn(A-3-6-44-48) true: warn(A-6-44-48), safe_string
...@@ -268,7 +268,7 @@ let addQuestions sk params qs = ...@@ -268,7 +268,7 @@ let addQuestions sk params qs =
let n = Array.length qs in let n = Array.length qs in
let qs = let qs =
Array.to_list qs |> Array.to_list qs |>
List.map (fun q -> q, Array.create (Array.length q.q_answers) 0) List.map (fun q -> q, Array.make (Array.length q.q_answers) 0)
in in
match qs with match qs with
| [] -> failwith "no questions" | [] -> failwith "no questions"
......
...@@ -121,12 +121,6 @@ end ...@@ -121,12 +121,6 @@ end
module String = struct module String = struct
include String include String
let map f s =
let n = String.length s in
let res = String.create n in
for i = 0 to n-1 do res.[i] <- f s.[i] done;
res
let startswith x s = let startswith x s =
let xn = String.length x and sn = String.length s in let xn = String.length x and sn = String.length s in
xn >= sn && String.sub x 0 sn = s xn >= sn && String.sub x 0 sn = s
......
...@@ -43,7 +43,6 @@ end ...@@ -43,7 +43,6 @@ end
module String : sig module String : sig
include module type of String include module type of String
val map : (char -> char) -> string -> string
val startswith : string -> string -> bool val startswith : string -> string -> bool
end end
......
...@@ -165,8 +165,8 @@ module MakeElection (G : GROUP) (M : RANDOM) = struct ...@@ -165,8 +165,8 @@ module MakeElection (G : GROUP) (M : RANDOM) = struct
(* the size of d is the number of disjuncts *) (* the size of d is the number of disjuncts *)
let n = Array.length d in let n = Array.length d in
assert (0 <= x && x < n); assert (0 <= x && x < n);
let proofs = Array.create n dummy_proof let proofs = Array.make n dummy_proof
and commitments = Array.create (2*n) g and commitments = Array.make (2*n) g
and total_challenges = ref Z.zero in and total_challenges = ref Z.zero in
(* compute fake proofs *) (* compute fake proofs *)
let f i = let f i =
...@@ -202,7 +202,7 @@ module MakeElection (G : GROUP) (M : RANDOM) = struct ...@@ -202,7 +202,7 @@ module MakeElection (G : GROUP) (M : RANDOM) = struct
G.check alpha && G.check beta && G.check alpha && G.check beta &&
let n = Array.length d in let n = Array.length d in
n = Array.length proofs && n = Array.length proofs &&
let commitments = Array.create (2*n) g let commitments = Array.make (2*n) g
and total_challenges = ref Z.zero in and total_challenges = ref Z.zero in
try try
for i = 0 to n-1 do for i = 0 to n-1 do
...@@ -227,7 +227,7 @@ module MakeElection (G : GROUP) (M : RANDOM) = struct ...@@ -227,7 +227,7 @@ module MakeElection (G : GROUP) (M : RANDOM) = struct
let make_d min max = let make_d min max =
let n = max - min + 1 in let n = max - min + 1 in
let d = Array.create n (invert (g **~ Z.of_int min)) in let d = Array.make n (invert (g **~ Z.of_int min)) in
for i = 1 to n-1 do for i = 1 to n-1 do
d.(i) <- d.(i-1) *~ invg d.(i) <- d.(i-1) *~ invg
done; done;
......
...@@ -74,12 +74,10 @@ let secure_rng () = () ...@@ -74,12 +74,10 @@ let secure_rng () = ()
let pseudo_rng _ () = () let pseudo_rng _ () = ()
let string_of_hex hex n = let string_of_hex hex n =
let res = String.create n in String.init n (fun i ->
for i = 0 to n-1 do
let c = int_of_string ("0x" ^ String.sub hex (2*i) 2) in let c = int_of_string ("0x" ^ String.sub hex (2*i) 2) in
res.[i] <- char_of_int c char_of_int c
done; )
res
let random_string rng n = let random_string rng n =
let () = rng () in let () = rng () in
......
...@@ -33,26 +33,24 @@ let b64_encode_compact x = ...@@ -33,26 +33,24 @@ let b64_encode_compact x =
Cryptokit.(transform_string (Base64.encode_compact ()) x) Cryptokit.(transform_string (Base64.encode_compact ()) x)
let int_msb i = let int_msb i =
let result = String.create 4 in let result = Bytes.create 4 in
result.[0] <- char_of_int (i lsr 24); Bytes.set result 0 (char_of_int (i lsr 24));
result.[1] <- char_of_int ((i lsr 16) land 0xff); Bytes.set result 1 (char_of_int ((i lsr 16) land 0xff));
result.[2] <- char_of_int ((i lsr 8) land 0xff); Bytes.set result 2 (char_of_int ((i lsr 8) land 0xff));
result.[3] <- char_of_int (i land 0xff); Bytes.set result 3 (char_of_int (i land 0xff));
result Bytes.to_string result
let xor a b = let xor a b =
let n = String.length a in let n = String.length a in
assert (n = String.length b); assert (n = String.length b);
let result = String.create n in String.init n (fun i ->
for i = 0 to n-1 do char_of_int (int_of_char a.[i] lxor int_of_char b.[i])
result.[i] <- char_of_int (int_of_char a.[i] lxor int_of_char b.[i]) )
done;
result
let pbkdf2 ~prf ~salt ~iterations ~size password = let pbkdf2 ~prf ~salt ~iterations ~size password =
let c = iterations - 1 in let c = iterations - 1 in
let hLen = (prf password)#hash_size in let hLen = (prf password)#hash_size in
let result = String.create (hLen * size) in let result = Bytes.create (hLen * size) in
let one_iteration i = let one_iteration i =
let u = Cryptokit.hash_string (prf password) (salt ^ int_msb i) in let u = Cryptokit.hash_string (prf password) (salt ^ int_msb i) in
let rec loop c u accu = let rec loop c u accu =
...@@ -66,7 +64,7 @@ let pbkdf2 ~prf ~salt ~iterations ~size password = ...@@ -66,7 +64,7 @@ let pbkdf2 ~prf ~salt ~iterations ~size password =
let offset = (i-1) * hLen in let offset = (i-1) * hLen in
String.blit (one_iteration i) 0 result offset hLen; String.blit (one_iteration i) 0 result offset hLen;
done; done;
result Bytes.to_string result
let remove_dashes x = let remove_dashes x =
let n = String.length x in let n = String.length x in
......
...@@ -72,13 +72,13 @@ module Make (P : PARSED_PARAMS) : S = struct ...@@ -72,13 +72,13 @@ module Make (P : PARSED_PARAMS) : S = struct
int_of_char (random_string (Lazy.force prng) 1).[0] int_of_char (random_string (Lazy.force prng) 1).[0]
let generate_raw_token () = let generate_raw_token () =
let res = String.create token_length in let res = Bytes.create token_length in
let rec loop i accu = let rec loop i accu =
if i < token_length then ( if i < token_length then (
let digit = random_char () mod 58 in let digit = random_char () mod 58 in
res.[i] <- digits.[digit]; Bytes.set res i digits.[digit];
loop (i+1) Z.(n58 * accu + of_int digit) loop (i+1) Z.(n58 * accu + of_int digit)
) else (res, accu) ) else (Bytes.to_string res, accu)
in loop 0 Z.zero in loop 0 Z.zero
let add_checksum (raw, value) = let add_checksum (raw, value) =
......
...@@ -206,14 +206,14 @@ let random_char () = ...@@ -206,14 +206,14 @@ let random_char () =
return (int_of_char (random_string rng 1).[0]) return (int_of_char (random_string rng 1).[0])
let generate_token () = let generate_token () =
let res = String.create token_length in let res = Bytes.create token_length in
let rec loop i = let rec loop i =
if i < token_length then ( if i < token_length then (
lwt digit = random_char () in lwt digit = random_char () in
let digit = digit mod 58 in let digit = digit mod 58 in
res.[i] <- b58_digits.[digit]; Bytes.set res i b58_digits.[digit];
loop (i+1) loop (i+1)
) else return res ) else return (Bytes.to_string res)
in loop 0 in loop 0
let string_of_user {user_domain; user_name} = let string_of_user {user_domain; user_name} =
......
...@@ -302,7 +302,7 @@ let () = File.register ...@@ -302,7 +302,7 @@ let () = File.register
(fun () () -> return !source_file) (fun () () -> return !source_file)
let do_get_randomness = let do_get_randomness =
let prng = Lazy.lazy_from_fun (Lwt_preemptive.detach (fun () -> let prng = Lazy.from_fun (Lwt_preemptive.detach (fun () ->
pseudo_rng (random_string secure_rng 16) pseudo_rng (random_string secure_rng 16)
)) in )) in
let mutex = Lwt_mutex.create () in let mutex = Lwt_mutex.create () in
...@@ -784,7 +784,7 @@ module Credgen = struct ...@@ -784,7 +784,7 @@ module Credgen = struct
(* FIXME: duplicate of Tool_credgen *) (* FIXME: duplicate of Tool_credgen *)
let get_random_char = let get_random_char =
let prng = Lazy.lazy_from_fun (Lwt_preemptive.detach (fun () -> let prng = Lazy.from_fun (Lwt_preemptive.detach (fun () ->
pseudo_rng (random_string secure_rng 16) pseudo_rng (random_string secure_rng 16)
)) in )) in
let mutex = Lwt_mutex.create () in let mutex = Lwt_mutex.create () in
...@@ -802,14 +802,14 @@ module Credgen = struct ...@@ -802,14 +802,14 @@ module Credgen = struct
let n53 = Z.of_int 53 let n53 = Z.of_int 53
let generate_raw_token () = let generate_raw_token () =
let res = String.create token_length in let res = Bytes.create token_length in
let rec loop i accu = let rec loop i accu =
if i < token_length then ( if i < token_length then (
lwt digit = get_random_char () in lwt digit = get_random_char () in
let digit = int_of_char digit mod 58 in let digit = int_of_char digit mod 58 in
res.[i] <- digits.[digit]; Bytes.set res i digits.[digit];
loop (i+1) Z.(n58 * accu + of_int digit) loop (i+1) Z.(n58 * accu + of_int digit)
) else return (res, accu) ) else return (Bytes.to_string res, accu)
in loop 0 Z.zero in loop 0 Z.zero
let add_checksum (raw, value) = let add_checksum (raw, value) =
......
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