From 5b5b996d64b316ebd301e920924c47265be64673 Mon Sep 17 00:00:00 2001 From: swrup Date: Sun, 2 Nov 2025 18:58:23 +0100 Subject: [PATCH] --- unikernel/unikernel.ml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/unikernel/unikernel.ml b/unikernel/unikernel.ml index 6e8ce596..47b96746 100644 --- a/unikernel/unikernel.ml +++ b/unikernel/unikernel.ml @@ -29,6 +29,9 @@ let alpn = let ( <.> ) f g x = f (g x) let always x _ = x +let map_err_to_string pp_err res = + Lwt.map (R.reword_error (R.msgf "%a" pp_err)) res + module Make (Certificate : Mirage_kv.RO) (Key : Mirage_kv.RO) @@ -36,14 +39,14 @@ module Make (Connect : Connect.S) (HTTP_server : Paf_mirage.S) = struct + let tls certificate_ro key_ro = let ( >>= ) = Lwt_result.bind in - Key.list key_ro Mirage_kv.Key.empty - |> Lwt.map (R.reword_error (R.msgf "%a" Key.pp_error)) + Key.list key_ro Mirage_kv.Key.empty |> map_err_to_string Key.pp_error >>= fun keys -> let keys, _ = List.partition (fun (_, t) -> t = `Value) keys in Certificate.list certificate_ro Mirage_kv.Key.empty - |> Lwt.map (R.reword_error (R.msgf "%a" Certificate.pp_error)) + |> map_err_to_string Certificate.pp_error >>= fun certificates -> let certificates, _ = List.partition (fun (_, t) -> t = `Value) certificates @@ -53,7 +56,7 @@ struct | ".gitkeep" -> Lwt.return acc | _ -> Certificate.get certificate_ro name - |> Lwt.map (R.reword_error (R.msgf "%a" Certificate.pp_error)) + |> map_err_to_string Certificate.pp_error >>= (Lwt.return <.> X509.Certificate.decode_pem_multiple) >>= fun certificates -> Lwt.return acc >>= fun acc -> @@ -65,7 +68,7 @@ struct | ".gitkeep" -> Lwt.return acc | _ -> Key.get key_ro name - |> Lwt.map (R.reword_error (R.msgf "%a" Key.pp_error)) + |> map_err_to_string Key.pp_error >>= (Lwt.return <.> X509.Private_key.decode_pem) >>= fun key -> Lwt.return acc >>= fun acc -> Lwt.return_ok ((name, key) :: acc)