diff --git a/src/fat.ml b/src/fat.ml index c69dd2cf..f06a829c 100644 --- a/src/fat.ml +++ b/src/fat.ml @@ -7,6 +7,12 @@ end) include Fat +type entry = Mfat.entry = { + name: string; + is_dir: bool; + size: int32; +} + type t = Mkernel.Block.t Mfat.t module type FS = sig diff --git a/src/secmod_eddsa.ml b/src/secmod_eddsa.ml index 9ee0b335..d0d8d6ca 100644 --- a/src/secmod_eddsa.ml +++ b/src/secmod_eddsa.ml @@ -57,12 +57,14 @@ let key_fpath k = let read_key fs 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 EddsaPrivateKey.of_octets data let write_eddsa fs fpath priv = Log.debug (fun m -> m "writing key file `%a`" Fpath.pp fpath); let data = EddsaPrivateKey.to_octets priv in + let fpath = Fpath.to_string fpath in Fat.write fs fpath data |> unwrap_msg 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 in 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 get_key_dir_contents fs dir = let* dir = Fpath.of_string dir |> unwrap_msg in - let* b = Fat.create fs dir |> unwrap_msg in - if b then Log.info (fun m -> m "created directory `%a`" Fpath.pp dir); + let dir = Fpath.to_string dir in + 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 - 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 Log.debug (fun m -> 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 Ok { fs; sm_key_priv; sm_pub; ht } in diff --git a/src/secmod_rsa.ml b/src/secmod_rsa.ml index 41b9159b..d2b9857d 100644 --- a/src/secmod_rsa.ml +++ b/src/secmod_rsa.ml @@ -80,21 +80,25 @@ let key_fpath k = let read_eddsa fs 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 EddsaPrivateKey.of_octets data let read_rsa fs 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 RsaPrivateKey.of_octets data let write_eddsa fs fpath priv = Log.debug (fun m -> m "writing key file `%a`" Fpath.pp fpath); let data = EddsaPrivateKey.to_octets priv in + let fpath = Fpath.to_string fpath in Fat.write fs fpath data |> unwrap_msg let write_rsa fs fpath priv = let data = RsaPrivateKey.to_octets priv in + let fpath = Fpath.to_string fpath in Fat.write fs fpath data |> unwrap_msg 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 in 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 get_key_dir_contents fs dir_fpath = - let* b = Fat.mkdir fs dir_fpath |> unwrap_msg in - if b then Log.info (fun m -> m "created directory `%a`" Fpath.pp dir_fpath); + let dir_fpath = Fpath.to_string dir_fpath in + 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 - 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 (* -- *)