This commit is contained in:
swrup 2026-02-20 09:13:00 +01:00
parent 46086e05ef
commit 75d2a2b65c

View file

@ -17,7 +17,7 @@ type key = {
type t = {
sm_key_priv: priv;
sm_key_pub: pub;
keys: key list;
mutable keys: key list;
}
let time_abs_of_string s =
@ -35,6 +35,11 @@ let time_abs_to_string abs =
|> Int64.to_int
|> string_of_int
let key_filename k =
let t1 = time_abs_to_string k.t1 in
let t2 = time_abs_to_string k.t2 in
Fmt.str "%s-%s" t1 t2
let read_key fname =
let fpath = Fpath.(v Cfg.key_dir / fname) in
let* data = Bos.OS.File.read fpath |> unwrap_err_msg in
@ -45,11 +50,7 @@ let write_eddsa fname priv =
let data = EddsaPrivateKey.to_octets priv in
Bos.OS.File.write fpath data |> unwrap_err_msg
let write_key t =
let t1 = time_abs_to_string t.t1 in
let t2 = time_abs_to_string t.t2 in
let fname = Fmt.str "%s-%s" t1 t2 in
write_eddsa fname t.priv
let write_key k = write_eddsa (key_filename k) k.priv
let split_in_periodes ~start ~end_ =
(* no overlap on first periode
@ -174,10 +175,21 @@ let sign ~pub s =
let data = EddsaSignature.sign ~key:k.priv s in
Ok data
let delete_key ~pub =
let k = List.find_opt (fun k -> k.pub = pub) t.keys in
match k with
| None -> Error "key not found"
| Some k ->
let l = List.filter (fun k -> k.pub <> pub) t.keys in
t.keys <- l;
(* rm file *)
let fname = key_filename k in
let fpath = Fpath.(v Cfg.key_dir / fname) in
let+ () = Bos.OS.File.delete ~must_exist:true fpath |> unwrap_err_msg in
()
(* TODO
- sign: check time
- purge
- revoke
- schedule tasks
- !lock