add Syntax.list_filter_map

This commit is contained in:
swrup 2026-02-23 11:45:27 +01:00 committed by Swrup
parent abfd35c425
commit b647223fc2
4 changed files with 76 additions and 72 deletions

View file

@ -122,20 +122,21 @@ let sm_key_fpath =
(* we load sm_key separately
we don't accept non-key files in key_dir *)
let load_key fpath =
match Fpath.equal (Fpath.normalize fpath) sm_key_fpath with
| true -> Ok None
| false -> (
match parse_filename fpath with
| None -> Fmt.error "invalid file `%a`" Fpath.pp fpath
| Some (t1, t2) ->
let* priv = read_key fpath in
let pub = EddsaPrivateKey.pub_of_priv priv in
Ok (Some { priv; pub; t1; t2 }))
match parse_filename fpath with
| None -> Fmt.error "invalid file `%a`" Fpath.pp fpath
| Some (t1, t2) ->
let+ priv = read_key fpath in
let pub = EddsaPrivateKey.pub_of_priv priv in
{ priv; pub; t1; t2 }
let load () =
let* l = get_key_dir_contents Cfg.key_dir in
let* l = list_map load_key l in
let keys = List.filter_map Fun.id l in
let l =
l
|> List.map Fpath.normalize
|> List.filter (fun fpath -> not @@ Fpath.equal fpath sm_key_fpath)
in
let* keys = list_map load_key l in
match keys with
| [] -> Ok None
| _l ->