This commit is contained in:
swrup 2026-03-12 13:11:10 +01:00
parent 2361fa13e1
commit 036b9bdec5
3 changed files with 29 additions and 7 deletions

View file

@ -7,6 +7,12 @@ end)
include Fat include Fat
type entry = Mfat.entry = {
name: string;
is_dir: bool;
size: int32;
}
type t = Mkernel.Block.t Mfat.t type t = Mkernel.Block.t Mfat.t
module type FS = sig module type FS = sig

View file

@ -57,12 +57,14 @@ let key_fpath k =
let read_key fs fpath = let read_key fs fpath =
Log.debug (fun m -> m "reading key file `%a`" Fpath.pp fpath); Log.debug (fun m -> m "reading key file `%a`" Fpath.pp fpath);
let fpath = Fpath.to_string fpath in
let* data = Fat.read fs fpath |> unwrap_msg in let* data = Fat.read fs fpath |> unwrap_msg in
EddsaPrivateKey.of_octets data EddsaPrivateKey.of_octets data
let write_eddsa fs fpath priv = let write_eddsa fs fpath priv =
Log.debug (fun m -> m "writing key file `%a`" Fpath.pp fpath); Log.debug (fun m -> m "writing key file `%a`" Fpath.pp fpath);
let data = EddsaPrivateKey.to_octets priv in let data = EddsaPrivateKey.to_octets priv in
let fpath = Fpath.to_string fpath in
Fat.write fs fpath data |> unwrap_msg Fat.write fs fpath data |> unwrap_msg
let write_key fs k = write_eddsa fs (key_fpath k) k.priv let write_key fs k = write_eddsa fs (key_fpath k) k.priv
@ -77,15 +79,20 @@ let delete_file fs fpath =
Fpath.pp fpath Fpath.pp fpath
in in
Log.debug (fun m -> m "delete key file `%a`" Fpath.pp fpath); Log.debug (fun m -> m "delete key file `%a`" Fpath.pp fpath);
let fpath = Fpath.to_string fpath in
let+ () = Fat.remove fs fpath |> unwrap_msg in let+ () = Fat.remove fs fpath |> unwrap_msg in
() ()
let get_key_dir_contents fs dir = let get_key_dir_contents fs dir =
let* dir = Fpath.of_string dir |> unwrap_msg in let* dir = Fpath.of_string dir |> unwrap_msg in
let* b = Fat.create fs dir |> unwrap_msg in let dir = Fpath.to_string dir in
if b then Log.info (fun m -> m "created directory `%a`" Fpath.pp dir); let* () = Fat.mkdir fs dir |> unwrap_msg in
Log.info (fun m -> m "created directory `%s`" dir);
let+ l = Fat.ls fs dir |> unwrap_msg in let+ l = Fat.ls fs dir |> unwrap_msg in
List.map Fpath.normalize l (* List.map Fpath.normalize l *)
let l = List.map (fun entry -> entry.Fat.name) l in
let l = List.map Fpath.v l in
l
(* -- *) (* -- *)
@ -164,7 +171,7 @@ let init fs =
let sm_key_priv, sm_pub = EddsaPrivateKey.generate () in let sm_key_priv, sm_pub = EddsaPrivateKey.generate () in
Log.debug (fun m -> Log.debug (fun m ->
m "generated secmod key: `%s`" (EddsaPublicKey.to_b32 sm_pub)); m "generated secmod key: `%s`" (EddsaPublicKey.to_b32 sm_pub));
let* () = write_eddsa sm_key_fpath sm_key_priv in let* () = write_eddsa fs sm_key_fpath sm_key_priv in
let ht = Hashtbl.create 0xff in let ht = Hashtbl.create 0xff in
Ok { fs; sm_key_priv; sm_pub; ht } Ok { fs; sm_key_priv; sm_pub; ht }
in in

View file

@ -80,21 +80,25 @@ let key_fpath k =
let read_eddsa fs fpath = let read_eddsa fs fpath =
Log.debug (fun m -> m "reading key file `%a`" Fpath.pp fpath); Log.debug (fun m -> m "reading key file `%a`" Fpath.pp fpath);
let fpath = Fpath.to_string fpath in
let* data = Fat.read fs fpath |> unwrap_msg in let* data = Fat.read fs fpath |> unwrap_msg in
EddsaPrivateKey.of_octets data EddsaPrivateKey.of_octets data
let read_rsa fs fpath = let read_rsa fs fpath =
Log.debug (fun m -> m "reading key file `%a`" Fpath.pp fpath); Log.debug (fun m -> m "reading key file `%a`" Fpath.pp fpath);
let fpath = Fpath.to_string fpath in
let* data = Fat.read fs fpath |> unwrap_msg in let* data = Fat.read fs fpath |> unwrap_msg in
RsaPrivateKey.of_octets data RsaPrivateKey.of_octets data
let write_eddsa fs fpath priv = let write_eddsa fs fpath priv =
Log.debug (fun m -> m "writing key file `%a`" Fpath.pp fpath); Log.debug (fun m -> m "writing key file `%a`" Fpath.pp fpath);
let data = EddsaPrivateKey.to_octets priv in let data = EddsaPrivateKey.to_octets priv in
let fpath = Fpath.to_string fpath in
Fat.write fs fpath data |> unwrap_msg Fat.write fs fpath data |> unwrap_msg
let write_rsa fs fpath priv = let write_rsa fs fpath priv =
let data = RsaPrivateKey.to_octets priv in let data = RsaPrivateKey.to_octets priv in
let fpath = Fpath.to_string fpath in
Fat.write fs fpath data |> unwrap_msg Fat.write fs fpath data |> unwrap_msg
let write_key fs k = write_rsa fs (key_fpath k) k.priv let write_key fs k = write_rsa fs (key_fpath k) k.priv
@ -109,14 +113,19 @@ let delete_file fs fpath =
Fpath.pp fpath Fpath.pp fpath
in in
Log.debug (fun m -> m "delete key file `%a`" Fpath.pp fpath); Log.debug (fun m -> m "delete key file `%a`" Fpath.pp fpath);
let fpath = Fpath.to_string fpath in
let+ () = Fat.remove fs fpath |> unwrap_msg in let+ () = Fat.remove fs fpath |> unwrap_msg in
() ()
let get_key_dir_contents fs dir_fpath = let get_key_dir_contents fs dir_fpath =
let* b = Fat.mkdir fs dir_fpath |> unwrap_msg in let dir_fpath = Fpath.to_string dir_fpath in
if b then Log.info (fun m -> m "created directory `%a`" Fpath.pp dir_fpath); let* () = Fat.mkdir fs dir_fpath |> unwrap_msg in
Log.info (fun m -> m "created directory `%s`" dir_fpath);
let+ l = Fat.ls fs dir_fpath |> unwrap_msg in let+ l = Fat.ls fs dir_fpath |> unwrap_msg in
List.map Fpath.normalize l (* List.map Fpath.normalize l *)
let l = List.map (fun entry -> entry.Fat.name) l in
let l = List.map Fpath.v l in
l
(* -- *) (* -- *)