diff --git a/src/http_management.ml b/src/http_management.ml index 50c9cad3..48a92b24 100644 --- a/src/http_management.ml +++ b/src/http_management.ml @@ -107,9 +107,7 @@ module Keys_post = struct let verify_denom_signature ~sm DenomSignature.{ h_denom_pub; master_sig } = let denom_hash = HashCode.to_denomination_hash h_denom_pub in let* denom = - Secmod.get_denoms sm - |> List.find_opt (fun (denom : Denom_data.t) -> denom.h_pub = denom_hash) - |> function + match Secmod.find_denom_data sm denom_hash with | None -> Fmt.error "404 not found, One of the keys for which a signature was provided \ @@ -135,9 +133,7 @@ module Keys_post = struct let verify_signkey_signature ~sm SignKeySignature.{ key; master_sig } = let* signkey = - Secmod.get_signkeys sm - |> List.find_opt (fun (signkey : Signkey_data.t) -> signkey.pub = key) - |> function + match Secmod.find_signkey_data sm key with | None -> Fmt.error "404 not found, One of the keys for which a signature was provided \ diff --git a/src/secmod.ml b/src/secmod.ml index 043c6ba0..7801e9b5 100644 --- a/src/secmod.ml +++ b/src/secmod.ml @@ -48,7 +48,6 @@ let verify_with_signkey t ~pub s ~msg = | None -> Error "secmod failure: public key not found." | Some signkey -> EddsaSignature.verify ~key:signkey.pub s ~msg -let get_sm_key_priv t = t.sm_key_priv let get_sm_key_pub t = t.sm_key_pub let get_signkeys t = @@ -59,6 +58,12 @@ let get_denoms t = Miou.Mutex.protect t.lock @@ fun () -> Hashtbl.to_seq_values t.dn_ht |> List.of_seq +let find_signkey_data t pub = + Miou.Mutex.protect t.lock @@ fun () -> Hashtbl.find_opt t.sk_ht pub + +let find_denom_data t h_denom = + Miou.Mutex.protect t.lock @@ fun () -> Hashtbl.find_opt t.dn_ht h_denom + let add_signkey_master_signatures conn t l = Miou.Mutex.protect t.lock @@ fun () -> list_iter diff --git a/src/secmod.mli b/src/secmod.mli index e4e427d7..7868cb6b 100644 --- a/src/secmod.mli +++ b/src/secmod.mli @@ -10,13 +10,14 @@ val verify_with_sm_key : t -> eddsa_sig -> msg:string -> (unit, string) result val verify_with_signkey : t -> pub:eddsa_pub -> eddsa_sig -> msg:string -> (unit, string) result -val get_sm_key_priv : t -> eddsa_priv val get_sm_key_pub : t -> eddsa_pub val get_signkeys : t -> Signkey_data.t list val get_denoms : t -> Denom_data.t list -val init : (module Pg.CONN) -> t +val find_signkey_data : t -> eddsa_pub -> Signkey_data.t option +val find_denom_data : t -> denomination_hash -> Denom_data.t option (* - management operations - *) +val init : (module Pg.CONN) -> t val add_signkey_master_signatures : (module Pg.CONN) ->