Commit 12dffa36 authored by Stephane Glondu's avatar Stephane Glondu Committed by Stéphane Glondu

Use Lwt.return_{none,some} when possible

parent 6c62906c
Pipeline #103610 passed with stages
in 24 minutes and 9 seconds
......@@ -52,8 +52,8 @@ let oidc_get_userinfo ocfg info =
let%lwt info = Ocsigen_stream.(string_of_stream 10000 (get stream)) in
let%lwt () = Ocsigen_stream.finalize stream `Success in
let x = oidc_userinfo_of_string info in
return (Some (match x.oidc_email with Some x -> x | None -> x.oidc_sub))
| None -> return None
return_some (match x.oidc_email with Some x -> x | None -> x.oidc_sub)
| None -> return_none
let oidc_get_name ocfg client_id client_secret code =
let content = [
......@@ -69,7 +69,7 @@ let oidc_get_name ocfg client_id client_secret code =
let%lwt info = Ocsigen_stream.(string_of_stream 10000 (get stream)) in
let%lwt () = Ocsigen_stream.finalize stream `Success in
oidc_get_userinfo ocfg info
| None -> return None
| None -> return_none
let oidc_handler params () =
Web_auth.run_post_login_handler "oidc" (fun _ _ authenticate ->
......
......@@ -162,7 +162,7 @@ let lookup_account ~service ~username ~email =
let username = String.trim username |> String.lowercase_ascii in
let email = email |> String.lowercase_ascii in
match get_password_db_fname service with
| None -> return None
| None -> return_none
| Some db ->
let%lwt db = Lwt_preemptive.detach Csv.load db in
match
......@@ -172,5 +172,5 @@ let lookup_account ~service ~username ~email =
| _ -> false
) db
with
| Some (u :: _ :: _ :: e :: _) when is_email e -> return (Some (u, e))
| _ -> return None
| Some (u :: _ :: _ :: e :: _) when is_email e -> return_some (u, e)
| _ -> return_none
......@@ -33,7 +33,7 @@ let ( / ) = Filename.concat
let get_draft_election uuid =
match%lwt read_file ~uuid "draft.json" with
| Some [x] -> return @@ Some (draft_election_of_string x)
| Some [x] -> return_some (draft_election_of_string x)
| _ -> return_none
let set_draft_election uuid se =
......@@ -41,7 +41,7 @@ let set_draft_election uuid se =
let get_election_result uuid =
match%lwt read_file ~uuid "result.json" with
| Some [x] -> return (Some (election_result_of_string Yojson.Safe.read_json x))
| Some [x] -> return_some (election_result_of_string Yojson.Safe.read_json x)
| _ -> return_none
let set_election_result_hidden uuid hidden =
......@@ -57,7 +57,7 @@ let get_election_result_hidden uuid =
| Some [x] ->
let t = datetime_of_string x in
if datetime_compare (now ()) t < 0 then
return (Some t)
return_some t
else
let%lwt () = set_election_result_hidden uuid None in
return_none
......@@ -168,7 +168,7 @@ let set_partial_decryptions uuid pds =
let get_decryption_tokens uuid =
match%lwt read_file ~uuid "decryption_tokens.json" with
| Some [x] -> return @@ Some (decryption_tokens_of_string x)
| Some [x] -> return_some (decryption_tokens_of_string x)
| _ -> return_none
let set_decryption_tokens uuid pds =
......@@ -177,7 +177,7 @@ let set_decryption_tokens uuid pds =
let get_raw_election uuid =
match%lwt read_file ~uuid "election.json" with
| Some [x] -> return (Some x)
| Some [x] -> return_some x
| _ -> return_none
let empty_metadata = {
......@@ -216,7 +216,7 @@ let get_elections_by_owner user =
Lwt_list.filter_map_s
(fun x ->
if x = "." || x = ".." then
return None
return_none
else (
try
let uuid = uuid_of_raw_string x in
......@@ -246,16 +246,16 @@ let get_elections_by_owner user =
let date = Option.get date default_archive_date in
return (`Archived, date)
in
return @@ Some (kind, uuid, date, election.e_params.e_name)
return_some (kind, uuid, date, election.e_params.e_name)
)
| _ -> return_none
)
| Some se ->
if se.se_owner = user then
let date = Option.get se.se_creation_date default_creation_date in
return @@ Some (`Draft, uuid, date, se.se_questions.t_name)
return_some (`Draft, uuid, date, se.se_questions.t_name)
else return_none
with _ -> return None
with _ -> return_none
)
)
......@@ -276,14 +276,14 @@ let get_passwords uuid =
SMap.add login (salt, hash) accu
| _ -> accu
) SMap.empty csv in
return @@ Some res
return_some res
let get_public_keys uuid =
read_file ~uuid "public_keys.jsons"
let get_private_key uuid =
match%lwt read_file ~uuid "private_key.json" with
| Some [x] -> return (Some (number_of_string x))
| Some [x] -> return_some (number_of_string x)
| _ -> return_none
let get_private_keys uuid =
......@@ -291,7 +291,7 @@ let get_private_keys uuid =
let get_threshold uuid =
match%lwt read_file ~uuid "threshold.json" with
| Some [x] -> return (Some x)
| Some [x] -> return_some x
| _ -> return_none
module StringMap = Map.Make (String)
......@@ -339,7 +339,7 @@ let get_ballot_by_hash uuid hash =
| _ ->
let%lwt ballot = read_file ~uuid ("ballots" / urlize hash) in
match ballot with
| Some [x] -> return (Some x)
| Some [x] -> return_some x
| _ -> return_none
let load_ballots uuid =
......@@ -349,7 +349,7 @@ let load_ballots uuid =
let%lwt ballots = Lwt_stream.to_list ballots in
Lwt_list.filter_map_s (fun x ->
match%lwt read_file (ballots_dir / x) with
| Some [x] -> return (Some x)
| Some [x] -> return_some x
| _ -> return_none
) ballots
) else return []
......@@ -377,7 +377,7 @@ let replace_ballot uuid ~hash ~rawballot =
let compute_encrypted_tally uuid =
let%lwt election = get_raw_election uuid in
match election with
| None -> return None
| None -> return_none
| Some election ->
let election = Election.of_string election in
let module W = (val Election.get_group election) in
......@@ -392,7 +392,7 @@ let compute_encrypted_tally uuid =
in
let tally = string_of_encrypted_tally E.G.write tally in
let%lwt () = write_file ~uuid (string_of_election_file ESETally) [tally] in
return (Some (num_tallied, sha256_b64 tally, tally))
return_some (num_tallied, sha256_b64 tally, tally)
module ExtendedRecordsCacheTypes = struct
type key = uuid
......
......@@ -170,10 +170,10 @@ Belenios Server" username uri
let confirm_link token =
links := filter_links_by_time !links;
match SMap.find_opt token !links with
| None -> Lwt.return None
| None -> Lwt.return_none
| Some x ->
links := SMap.remove token !links;
Lwt.return (Some (x.service, x.address, x.kind))
Lwt.return_some (x.service, x.address, x.kind)
let cracklib =
let x = "cracklib-check" in (x, [| x |])
......@@ -191,4 +191,4 @@ let cracklib_check password =
| None ->
let%lwt x = Lwt_process.pmap ~env:[| "LANG=C" |] cracklib password in
Lwt.return (extract_comment x)
| Some _ -> Lwt.return (Some "newline in password")
| Some _ -> Lwt.return_some "newline in password"
......@@ -282,10 +282,10 @@ let delete_election uuid =
let%lwt de_trustees_threshold =
let%lwt threshold = Web_persist.get_threshold uuid in
match threshold with
| None -> return None
| None -> return_none
| Some x ->
let x = threshold_parameters_of_string Yojson.Safe.read_json x in
return (Some x.t_threshold)
return_some x.t_threshold
in
let%lwt pks = Web_persist.get_public_keys uuid in
let%lwt voters = Web_persist.get_voters uuid in
......@@ -380,10 +380,10 @@ let () = Html.register ~service:admin
let%lwt site_user = Eliom_reference.get Web_state.site_user in
let%lwt elections =
match site_user with
| None -> return None
| None -> return_none
| Some u ->
let%lwt elections = get_elections_by_owner_sorted u in
return @@ Some elections
return_some elections
in
T.admin ~elections ()
)
......@@ -2223,8 +2223,8 @@ let () =
let%lwt error =
let%lwt ok = Web_signup.check_captcha ~challenge ~response in
if ok then
if is_email email then return None else return (Some BadAddress)
else return (Some BadCaptcha)
if is_email email then return_none else return_some BadAddress
else return_some BadCaptcha
in
match error with
| None ->
......@@ -2255,8 +2255,8 @@ let () =
(fun service (challenge, (response, (email, username))) ->
let%lwt error =
let%lwt ok = Web_signup.check_captcha ~challenge ~response in
if ok then return None
else return (Some BadCaptcha)
if ok then return_none
else return_some BadCaptcha
in
match error with
| None ->
......@@ -2344,7 +2344,7 @@ let extract_automatic_data_draft uuid_s =
let contact = se.se_metadata.e_contact in
let t = Option.get se.se_creation_date default_creation_date in
let next_t = datetime_add t (day days_to_delete) in
return @@ Some (`Destroy, uuid, next_t, name, contact)
return_some (`Destroy, uuid, next_t, name, contact)
let extract_automatic_data_validated uuid_s =
let uuid = uuid_of_raw_string uuid_s in
......@@ -2362,17 +2362,17 @@ let extract_automatic_data_validated uuid_s =
let%lwt t = Web_persist.get_election_date `Validation uuid in
let t = Option.get t default_validation_date in
let next_t = datetime_add t (day days_to_delete) in
return @@ Some (`Delete, uuid, next_t, name, contact)
return_some (`Delete, uuid, next_t, name, contact)
| `Tallied ->
let%lwt t = Web_persist.get_election_date `Tally uuid in
let t = Option.get t default_tally_date in
let next_t = datetime_add t (day days_to_archive) in
return @@ Some (`Archive, uuid, next_t, name, contact)
return_some (`Archive, uuid, next_t, name, contact)
| `Archived ->
let%lwt t = Web_persist.get_election_date `Archive uuid in
let t = Option.get t default_archive_date in
let next_t = datetime_add t (day days_to_delete) in
return @@ Some (`Delete, uuid, next_t, name, contact)
return_some (`Delete, uuid, next_t, name, contact)
let try_extract extract x =
try%lwt extract x with _ -> return_none
......
......@@ -30,8 +30,8 @@ let election_user = Eliom_reference.eref ~scope None
let get_election_user uuid =
match%lwt Eliom_reference.get election_user with
| Some (u, x) when u = uuid -> return (Some x)
| _ -> return None
| Some (u, x) when u = uuid -> return_some x
| _ -> return_none
let ballot = Eliom_reference.eref ~scope None
let cast_confirmed = Eliom_reference.eref ~scope None
......
......@@ -2524,7 +2524,7 @@ let tally_trustees election trustee_id token () =
let%lwt encrypted_private_key =
match%lwt Web_persist.get_private_keys uuid with
| None -> return_none
| Some keys -> return (Some (List.nth keys (trustee_id-1)))
| Some keys -> return_some (List.nth keys (trustee_id-1))
in
let content = [
p [pcdata "It is now time to compute your partial decryption factors."];
......
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