From 464de6d6b864b58cfdc6d33651589b60cbd371a4 Mon Sep 17 00:00:00 2001 From: MBourgoin Date: Tue, 22 Jan 2019 16:38:55 +0100 Subject: [PATCH] Client: improve password file reading --- src/lib_signer_backends/encrypted.ml | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/lib_signer_backends/encrypted.ml b/src/lib_signer_backends/encrypted.ml index 2c1afe5e8..4087cd960 100644 --- a/src/lib_signer_backends/encrypted.ml +++ b/src/lib_signer_backends/encrypted.ml @@ -156,25 +156,15 @@ let rec interactive_decrypt_loop | None -> interactive_decrypt_loop cctxt ?name ~encrypted_sk algo -(* FixMe : this could be done more elegantly *) -let read_all_lines filename = - let lines = ref [] in - let chan = open_in filename in - try - while true; do - lines := input_line chan :: !lines - done; !lines - with End_of_file -> - close_in chan; - List.rev !lines - (* add all passwords in [filename] to the list of known passwords *) let password_file_load = function |Some filename -> if Sys.file_exists filename then begin - let l = read_all_lines filename in - let l = List.map MBytes.of_string l in - passwords := !passwords @ l ; + let stream = Lwt_io.lines_of_file filename in + Lwt_stream.iter + (fun p -> + passwords := MBytes.of_string p :: !passwords) + stream >>= fun () -> return_unit end else