rm non-NBO Bin.t; rename time modules

This commit is contained in:
swrup 2026-02-24 17:51:30 +01:00
parent 4f473c003a
commit d69b49a335
13 changed files with 306 additions and 359 deletions

View file

@ -11,8 +11,8 @@ module Cfg = Config.Exchange_secmod_eddsa
type key = {
priv: EddsaPrivateKey.t;
pub: EddsaPublicKey.t;
t1: Absolute.t;
t2: Absolute.t;
t1: TimeAbsolute.t;
t2: TimeAbsolute.t;
}
type t = {
@ -24,7 +24,7 @@ type t = {
let parse_filename =
let scan_filename s =
Scanf.sscanf_opt s "%Lu-%Lu" (fun t1 t2 ->
(Absolute.of_s t1, Absolute.of_s t2))
(TimeAbsolute.of_s t1, TimeAbsolute.of_s t2))
in
fun fpath -> scan_filename (Fpath.filename fpath)
@ -81,18 +81,18 @@ let gen_key t1 t2 =
(EddsaPublicKey.to_b32 pub));
{ priv; pub; t1; t2 }
let sort_keys l = List.sort (fun a b -> Absolute.compare a.t2 b.t2) l
let sort_keys l = List.sort (fun a b -> TimeAbsolute.compare a.t2 b.t2) l
let split_in_periodes ~start ~end_ =
assert (start < end_);
(* no overlap on first periode *)
let t1 = start in
let t2 = Absolute.add start Cfg.duration in
let t2 = TimeAbsolute.add start Cfg.duration in
let acc = [ (t1, t2) ] in
let start = t2 in
let rec go acc start end_ =
let t1 = Absolute.sub start Cfg.overlap_duration in
let t2 = Absolute.add start Cfg.duration in
let t1 = TimeAbsolute.sub start Cfg.overlap_duration in
let t2 = TimeAbsolute.add start Cfg.duration in
if t2 > end_ then acc else go ((t1, t2) :: acc) t2 end_
in
go acc start end_
@ -103,10 +103,10 @@ let gen_additional_keys_until_lookahead ~now l =
let start =
match List.rev (sort_keys l) with
| [] -> now
| hd :: _ -> Absolute.sub hd.t2 Cfg.overlap_duration
| hd :: _ -> TimeAbsolute.sub hd.t2 Cfg.overlap_duration
in
let end_ = Absolute.add now Cfg.lookahead_sign in
if Absolute.compare start end_ >= 0 then []
let end_ = TimeAbsolute.add now Cfg.lookahead_sign in
if TimeAbsolute.compare start end_ >= 0 then []
else
let periodes = split_in_periodes ~start ~end_ in
let new_keys = List.map (fun (t1, t2) -> gen_key t1 t2) periodes in
@ -159,19 +159,14 @@ let init () =
let ht = Hashtbl.create 0xff in
Ok { sm_key_priv; sm_pub; ht }
in
let now = Absolute.of_ptime (Ptime_clock.now ()) in
let now = TimeAbsolute.of_ptime (Ptime_clock.now ()) in
let keys = List.of_seq @@ Hashtbl.to_seq_values t.ht in
let new_keys = gen_additional_keys_until_lookahead ~now keys in
let () = List.iter (fun k -> Hashtbl.replace t.ht k.pub k) keys in
let+ () = list_iter write_key new_keys in
t
type info = eddsa_pub * Time.Absolute.t * Time.Absolute.t
module Make () = struct
type pub = EddsaPublicKey.t
type info = EddsaPublicKey.t * Time.Absolute.t * Time.Absolute.t
let t =
match init () with
| Error e -> Fmt.failwith "secmod_eddsa initialization failure: %s." e
@ -193,7 +188,7 @@ module Make () = struct
let _delete_outdated ~now =
Hashtbl.to_seq_values t.ht
|> List.of_seq
|> List.filter (fun k -> Absolute.compare now k.t2 >= 0)
|> List.filter (fun k -> TimeAbsolute.compare now k.t2 >= 0)
|> List.map (fun k -> k.pub)
|> list_iter delete