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