diff --git a/src/http_info.ml b/src/http_info.ml index 53039402..a8793388 100644 --- a/src/http_info.ml +++ b/src/http_info.ml @@ -68,7 +68,7 @@ let mk_keys ~db_conn (module Keys : Keys.S) ~last_issue_date = | Some timestamp -> List.find_map (fun v -> - if Timestamp.compare v.Denomination.stamp_start timestamp = 0 then + if Timestamp.equal v.Denomination.stamp_start timestamp then Some v.stamp_start else None) denom_l @@ -77,20 +77,24 @@ let mk_keys ~db_conn (module Keys : Keys.S) ~last_issue_date = | None -> denom_l | Some timestamp -> List.filter - (fun v -> Timestamp.compare v.Denomination.stamp_start timestamp >= 0) + (fun v -> Timestamp.geq v.Denomination.stamp_start timestamp) denom_l in let* denominations = Denomination.make_denom_group_sorted denom_l in let* signkeys = Keys.signkeys () in - let signkeys = List.map Api.SignKey.of_signkey signkeys in (* the eddsa pub key used to sign exchange_sig *) let* exchange_pub = - match signkeys with - | [] -> Fmt.error "exchange has no active signkey" - | sk :: _ -> Ok sk.SignKey.key + let now = Timestamp.of_ptime (Ptime_clock.now ()) in + let opt = + List.find_opt (fun sk -> Signkey.is_valid_at ~timestamp:now sk) signkeys + in + match opt with + | None -> Fmt.error "exchange has no active signkey" + | Some sk -> Ok sk.pub in + let signkeys = List.map Api.SignKey.of_signkey signkeys in (* ! depends on denominations order *) let exchange_sig = diff --git a/src/http_management.ml b/src/http_management.ml index 47b4a139..1203dce0 100644 --- a/src/http_management.ml +++ b/src/http_management.ml @@ -164,7 +164,7 @@ module Auditors = struct Logs.info (fun m -> m "enabled auditor"); () | Some auditor -> - if Timestamp.compare auditor.last_change validity_start > 0 then + if Timestamp.geq auditor.last_change validity_start then Error "database has more recent auditor data for this auditor public key" else @@ -200,7 +200,7 @@ module Auditors_disable = struct match opt with | None -> Error "auditor not found" | Some auditor -> ( - match Timestamp.compare auditor.last_change validity_end > 0 with + match Timestamp.geq auditor.last_change validity_end with | true -> Error "database has more recent auditor data for this auditor public \ diff --git a/src/signkey.ml b/src/signkey.ml index f0035e1f..8d58e117 100644 --- a/src/signkey.ml +++ b/src/signkey.ml @@ -7,3 +7,6 @@ type t = { stamp_end: Timestamp.t; master_sig: Signatures.ExchangeSigningKeyValidity.t; } + +let is_valid_at ~timestamp sk = + Timestamp.geq sk.stamp_start timestamp && Timestamp.lt timestamp sk.stamp_end diff --git a/src/time.ml b/src/time.ml index e65cad41..b05cf5fb 100644 --- a/src/time.ml +++ b/src/time.ml @@ -97,6 +97,11 @@ module Timestamp = struct let never = uint64_max let zero = 0L let compare = Int64.unsigned_compare + let gt a b = compare a b > 0 + let geq a b = compare a b >= 0 + let lt a b = compare a b < 0 + let leq a b = compare a b <= 0 + let equal a b = compare a b = 0 let min a b = if compare a b < 0 then a else b let max a b = if compare a b > 0 then a else b diff --git a/src/time.mli b/src/time.mli index ce2e398a..dc4bd841 100644 --- a/src/time.mli +++ b/src/time.mli @@ -37,6 +37,11 @@ module Timestamp : sig val never : t val zero : t val compare : t -> t -> int + val gt : t -> t -> bool + val geq : t -> t -> bool + val lt : t -> t -> bool + val leq : t -> t -> bool + val equal : t -> t -> bool val min : t -> t -> t val max : t -> t -> t val diff : t -> t -> TimeRelative.t