From 355b24ff4401b63b2d5a90664077be80d76b9630 Mon Sep 17 00:00:00 2001 From: swrup Date: Tue, 3 Mar 2026 10:48:14 +0100 Subject: [PATCH] s/unwrap_err_msg/unwrap_msg/ --- src/crypto.ml | 4 ++-- src/mte_management.ml | 24 ++++++++++++------------ src/secmod_eddsa.ml | 16 +++++++--------- src/secmod_rsa.ml | 16 ++++++++-------- src/syntax.ml | 2 +- test/validate_response.ml | 2 +- tools/offline_impl.ml | 8 ++++---- 7 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/crypto.ml b/src/crypto.ml index 5402e12b..5c480085 100644 --- a/src/crypto.ml +++ b/src/crypto.ml @@ -60,7 +60,7 @@ module Binary_format_rsa = struct let* arr = z_array_of_octets ~nb:2 s in match arr with | [| n; e |] -> - let+ pub = Mirage_crypto_pk.Rsa.pub ~n ~e |> unwrap_err_msg in + let+ pub = Mirage_crypto_pk.Rsa.pub ~n ~e |> unwrap_msg in pub | _ -> assert false @@ -74,7 +74,7 @@ module Binary_format_rsa = struct match arr with | [| e; d; n; p; q; dp; dq; q' |] -> let+ priv = - Mirage_crypto_pk.Rsa.priv ~e ~d ~n ~p ~q ~dp ~dq ~q' |> unwrap_err_msg + Mirage_crypto_pk.Rsa.priv ~e ~d ~n ~p ~q ~dp ~dq ~q' |> unwrap_msg in priv | _ -> assert false diff --git a/src/mte_management.ml b/src/mte_management.ml index a5c45e55..8960717a 100644 --- a/src/mte_management.ml +++ b/src/mte_management.ml @@ -33,7 +33,7 @@ module Keys_post = struct Logs.info (fun m -> m "POST /management/keys/"); let keys = Vif.Server.device Devices.keys server in let res = - let* v = Vif.Request.of_json req |> unwrap_err_msg in + let* v = Vif.Request.of_json req |> unwrap_msg in let* () = verify keys v in let* () = do_ keys v in Ok () @@ -59,7 +59,7 @@ module Denom_revoke = struct let keys = Vif.Server.device Devices.keys server in let res = let* h_denom_pub = Crypto.DenominationHash.of_b32 h_denom_pub in - let* v = Vif.Request.of_json req |> unwrap_err_msg in + let* v = Vif.Request.of_json req |> unwrap_msg in let* () = verify keys h_denom_pub v in let* () = do_ keys h_denom_pub v in Ok () @@ -85,7 +85,7 @@ module Signkey_revoke = struct let keys = Vif.Server.device Devices.keys server in let res = let* exchange_pub = Crypto.EddsaPublicKey.of_b32 exchange_pub in - let* v = Vif.Request.of_json req |> unwrap_err_msg in + let* v = Vif.Request.of_json req |> unwrap_msg in let* () = verify keys exchange_pub v in let* () = do_ keys exchange_pub v in Ok () @@ -136,7 +136,7 @@ module Auditors = struct let keys = Vif.Server.device Devices.keys server in let db_conn = Vif.Server.device Devices.db_connection server in let res = - let* v = Vif.Request.of_json req |> unwrap_err_msg in + let* v = Vif.Request.of_json req |> unwrap_msg in let* () = verify keys v in let* () = do_ ~db_conn v in Ok () @@ -182,7 +182,7 @@ module Auditors_disable = struct let db_conn = Vif.Server.device Devices.db_connection server in let res = let* auditor_pub = Crypto.EddsaPublicKey.of_b32 auditor_pub in - let* v = Vif.Request.of_json req |> unwrap_err_msg in + let* v = Vif.Request.of_json req |> unwrap_msg in let* () = verify keys auditor_pub v in let* () = do_ ~db_conn auditor_pub v in Ok () @@ -241,7 +241,7 @@ module Wire_fee = struct let keys = Vif.Server.device Devices.keys server in let db_conn = Vif.Server.device Devices.db_connection server in let res = - let* v = Vif.Request.of_json req |> unwrap_err_msg in + let* v = Vif.Request.of_json req |> unwrap_msg in let* () = verify keys v in let* () = do_ ~db_conn v in Ok () @@ -287,7 +287,7 @@ module Global_fees = struct Logs.info (fun m -> m "POST /management/global-fees/"); let db_conn = Vif.Server.device Devices.db_connection server in let res = - let* v = Vif.Request.of_json req |> unwrap_err_msg in + let* v = Vif.Request.of_json req |> unwrap_msg in let* () = verify v in let* () = do_ ~db_conn v in Ok () @@ -403,7 +403,7 @@ module Wire = struct let keys = Vif.Server.device Devices.keys server in let db_conn = Vif.Server.device Devices.db_connection server in let res = - let* v = Vif.Request.of_json req |> unwrap_err_msg in + let* v = Vif.Request.of_json req |> unwrap_msg in let* () = verify keys v in let* () = do_ ~db_conn v in Ok () @@ -442,7 +442,7 @@ module Wire_disable = struct let keys = Vif.Server.device Devices.keys server in let db_conn = Vif.Server.device Devices.db_connection server in let res = - let* v = Vif.Request.of_json req |> unwrap_err_msg in + let* v = Vif.Request.of_json req |> unwrap_msg in let* () = verify keys v in let* () = do_ ~db_conn v in Ok () @@ -492,7 +492,7 @@ module Drain = struct let keys = Vif.Server.device Devices.keys server in let db_conn = Vif.Server.device Devices.db_connection server in let res = - let* v = Vif.Request.of_json req |> unwrap_err_msg in + let* v = Vif.Request.of_json req |> unwrap_msg in let* () = verify keys v in let* () = do_ ~db_conn v in Ok () @@ -532,7 +532,7 @@ module AmlOfficer = struct let keys = Vif.Server.device Devices.keys server in let db_conn = Vif.Server.device Devices.db_connection server in let res = - let* v = Vif.Request.of_json req |> unwrap_err_msg in + let* v = Vif.Request.of_json req |> unwrap_msg in let* () = verify keys v in let* () = do_ ~db_conn v in Ok () @@ -574,7 +574,7 @@ module Partners = struct let keys = Vif.Server.device Devices.keys server in let db_conn = Vif.Server.device Devices.db_connection server in let res = - let* v = Vif.Request.of_json req |> unwrap_err_msg in + let* v = Vif.Request.of_json req |> unwrap_msg in let* () = verify keys v in let* () = do_ ~db_conn v in Ok () diff --git a/src/secmod_eddsa.ml b/src/secmod_eddsa.ml index 2eece202..12d1041e 100644 --- a/src/secmod_eddsa.ml +++ b/src/secmod_eddsa.ml @@ -46,13 +46,13 @@ let key_fpath k = let read_key fpath = Log.debug (fun m -> m "reading key file `%a`" Fpath.pp fpath); - let* data = Bos.OS.File.read fpath |> unwrap_err_msg in + let* data = Bos.OS.File.read fpath |> unwrap_msg in EddsaPrivateKey.of_octets data let write_eddsa fpath priv = Log.debug (fun m -> m "writing key file `%a`" Fpath.pp fpath); let data = EddsaPrivateKey.to_octets priv in - Bos.OS.File.write fpath data |> unwrap_err_msg + Bos.OS.File.write fpath data |> unwrap_msg let write_key k = write_eddsa (key_fpath k) k.priv @@ -66,16 +66,14 @@ let delete_file fpath = Fpath.pp fpath in Log.debug (fun m -> m "delete key file `%a`" Fpath.pp fpath); - let+ () = Bos.OS.File.delete ~must_exist:true fpath |> unwrap_err_msg in + let+ () = Bos.OS.File.delete ~must_exist:true fpath |> unwrap_msg in () let get_key_dir_contents dir = - let* dir = Fpath.of_string dir |> unwrap_err_msg in - let* b = Bos.OS.Dir.create ~mode:0o700 dir |> unwrap_err_msg in + let* dir = Fpath.of_string dir |> unwrap_msg in + let* b = Bos.OS.Dir.create ~mode:0o700 dir |> unwrap_msg in if b then Log.info (fun m -> m "created directory `%a`" Fpath.pp dir); - let+ l = - Bos.OS.Dir.contents ~dotfiles:false ~rel:false dir |> unwrap_err_msg - in + let+ l = Bos.OS.Dir.contents ~dotfiles:false ~rel:false dir |> unwrap_msg in List.map Fpath.normalize l (* -- *) @@ -121,7 +119,7 @@ let gen_additional_keys_until_lookahead ~now l = let sm_key_fpath = Result.get_ok @@ - let+ fpath = Fpath.of_string Cfg.sm_priv_key |> unwrap_err_msg in + let+ fpath = Fpath.of_string Cfg.sm_priv_key |> unwrap_msg in Fpath.normalize fpath (* we load sm_key separately diff --git a/src/secmod_rsa.ml b/src/secmod_rsa.ml index 698c8de4..edc70476 100644 --- a/src/secmod_rsa.ml +++ b/src/secmod_rsa.ml @@ -80,22 +80,22 @@ let key_fpath k = let read_eddsa fpath = Log.debug (fun m -> m "reading key file `%a`" Fpath.pp fpath); - let* data = Bos.OS.File.read fpath |> unwrap_err_msg in + let* data = Bos.OS.File.read fpath |> unwrap_msg in EddsaPrivateKey.of_octets data let read_rsa fpath = Log.debug (fun m -> m "reading key file `%a`" Fpath.pp fpath); - let* data = Bos.OS.File.read fpath |> unwrap_err_msg in + let* data = Bos.OS.File.read fpath |> unwrap_msg in RsaPrivateKey.of_octets data let write_eddsa fpath priv = Log.debug (fun m -> m "writing key file `%a`" Fpath.pp fpath); let data = EddsaPrivateKey.to_octets priv in - Bos.OS.File.write fpath data |> unwrap_err_msg + Bos.OS.File.write fpath data |> unwrap_msg let write_rsa fpath priv = let data = RsaPrivateKey.to_octets priv in - Bos.OS.File.write fpath data |> unwrap_err_msg + Bos.OS.File.write fpath data |> unwrap_msg let write_key k = write_rsa (key_fpath k) k.priv @@ -109,14 +109,14 @@ let delete_file fpath = Fpath.pp fpath in Log.debug (fun m -> m "delete key file `%a`" Fpath.pp fpath); - let+ () = Bos.OS.File.delete ~must_exist:true fpath |> unwrap_err_msg in + let+ () = Bos.OS.File.delete ~must_exist:true fpath |> unwrap_msg in () let get_key_dir_contents dir_fpath = - let* b = Bos.OS.Dir.create ~mode:0o700 dir_fpath |> unwrap_err_msg in + let* b = Bos.OS.Dir.create ~mode:0o700 dir_fpath |> unwrap_msg in if b then Log.info (fun m -> m "created directory `%a`" Fpath.pp dir_fpath); let+ l = - Bos.OS.Dir.contents ~dotfiles:false ~rel:false dir_fpath |> unwrap_err_msg + Bos.OS.Dir.contents ~dotfiles:false ~rel:false dir_fpath |> unwrap_msg in List.map Fpath.normalize l @@ -168,7 +168,7 @@ let gen_additional_keys_until_lookahead ~now ~section_name l = let sm_key_fpath = Result.get_ok @@ - let+ fpath = Fpath.of_string Cfg.sm_priv_key |> unwrap_err_msg in + let+ fpath = Fpath.of_string Cfg.sm_priv_key |> unwrap_msg in Fpath.normalize fpath (* we load sm_key separately diff --git a/src/syntax.ml b/src/syntax.ml index aafcfbcf..619136d9 100644 --- a/src/syntax.ml +++ b/src/syntax.ml @@ -5,7 +5,7 @@ let ( let+ ) o f = match o with Ok v -> Ok (f v) | Error _ as e -> e use polymorphic variant for errors use GANA error codes: https://git.gnunet.org/gana.git/tree/gnu-taler-error-codes/registry.rec *) -let unwrap_err_msg o = match o with Error (`Msg e) -> Error e | Ok v -> Ok v +let unwrap_msg o = match o with Error (`Msg e) -> Error e | Ok v -> Ok v let unwrap_err_caqti o = match o with Error err -> Fmt.error "%a" Caqti_error.pp err | Ok v -> Ok v diff --git a/test/validate_response.ml b/test/validate_response.ml index 53dacb61..77a3c718 100644 --- a/test/validate_response.ml +++ b/test/validate_response.ml @@ -129,7 +129,7 @@ let keys_cmd = @@ let+ input = input in let* content = - Result.bind (Fpath.of_string input) Bos.OS.File.read |> unwrap_err_msg + Result.bind (Fpath.of_string input) Bos.OS.File.read |> unwrap_msg in keys content diff --git a/tools/offline_impl.ml b/tools/offline_impl.ml index b327b99f..d3ab9e41 100644 --- a/tools/offline_impl.ml +++ b/tools/offline_impl.ml @@ -145,10 +145,10 @@ end (* -- *) -let read_file fname = Bos.OS.File.read (Fpath.v fname) |> unwrap_err_msg +let read_file fname = Bos.OS.File.read (Fpath.v fname) |> unwrap_msg let write_file fname content = - Bos.OS.File.write (Fpath.v fname) content |> unwrap_err_msg + Bos.OS.File.write (Fpath.v fname) content |> unwrap_msg let read_master_key_file filename = let* master_key = read_file filename in @@ -167,7 +167,7 @@ let download ~output ~url = % "-X" % "GET" % url) - |> unwrap_err_msg + |> unwrap_msg let upload ~input ~url = let open Bos in @@ -185,7 +185,7 @@ let upload ~input ~url = % "--data" % ("@" ^ input) % url) - |> unwrap_err_msg + |> unwrap_msg let setup ~output ~output_pubkey = Mirage_crypto_rng_unix.use_default ();