s/unwrap_err_/unwrap_/

This commit is contained in:
swrup 2026-03-03 10:48:14 +01:00
parent 21e6a47007
commit e59762a393
10 changed files with 68 additions and 74 deletions

View file

@ -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

View file

@ -48,8 +48,8 @@ module Make (Conn : Pg.CONN) : S = struct
| Ok v -> v
(* - *)
let find_signkey pub = Pg.find_signkey conn pub |> unwrap_err_caqti
let find_denomination h_pub = Pg.find_denom conn h_pub |> unwrap_err_caqti
let find_signkey pub = Pg.find_signkey conn pub |> unwrap_caqti
let find_denomination h_pub = Pg.find_denom conn h_pub |> unwrap_caqti
let warn_key_state =
let first = ref true in
@ -64,7 +64,7 @@ module Make (Conn : Pg.CONN) : S = struct
let signkeys () : Signkey.t list result =
let now = Timestamp.of_ptime @@ Ptime_clock.now () in
let+ l = Pg.get_signkeys conn ~now |> unwrap_err_caqti in
let+ l = Pg.get_signkeys conn ~now |> unwrap_caqti in
let missing_l, l =
List.partition
(fun sk -> Option.is_none @@ Sm_eddsa.find_key sk.Signkey.pub)
@ -78,7 +78,7 @@ module Make (Conn : Pg.CONN) : S = struct
l
let denominations () =
let+ l = Pg.get_denominations conn () |> unwrap_err_caqti in
let+ l = Pg.get_denominations conn () |> unwrap_caqti in
let missing_l, l =
List.partition
(fun dn -> Option.is_none @@ Sm_rsa.find_key dn.Denomination.h_pub)
@ -200,7 +200,7 @@ module Make (Conn : Pg.CONN) : S = struct
let make_future_keys_response () =
let now = Timestamp.of_ptime @@ Ptime_clock.now () in
(* get keys from database to filter out keys already certified *)
let* sk_db_l = Pg.get_signkeys conn ~now |> unwrap_err_caqti in
let* sk_db_l = Pg.get_signkeys conn ~now |> unwrap_caqti in
let sk_ht = Hashtbl.create 0xff in
List.iter (fun sk -> Hashtbl.replace sk_ht sk.Signkey.pub ()) sk_db_l;
let future_signkeys =
@ -208,7 +208,7 @@ module Make (Conn : Pg.CONN) : S = struct
|> List.filter (fun (pub, _) -> not @@ Hashtbl.mem sk_ht pub)
|> List.map make_future_sk
in
let* dn_db_l = Pg.get_denominations conn () |> unwrap_err_caqti in
let* dn_db_l = Pg.get_denominations conn () |> unwrap_caqti in
let dn_ht = Hashtbl.create 0xff in
List.iter (fun dn -> Hashtbl.replace dn_ht dn.Denomination.h_pub ()) dn_db_l;
let future_denoms =
@ -302,7 +302,7 @@ module Make (Conn : Pg.CONN) : S = struct
(* rebuild it *)
let future_sk = make_future_sk (pub, (t1, t2)) in
let sk = sk_of_future_sk future_sk master_sig in
let+ () = Pg.insert_signkey conn sk |> unwrap_err_caqti in
let+ () = Pg.insert_signkey conn sk |> unwrap_caqti in
Logs.info (fun m ->
m "certified signkey `%s`" (EddsaPublicKey.to_b32 sk.pub));
())
@ -320,7 +320,7 @@ module Make (Conn : Pg.CONN) : S = struct
| None ->
let future_dn = make_future_dn (h_pub, (section_name, pub, t1)) in
let dn = dn_of_future_dn future_dn h_pub master_sig in
let+ () = Pg.insert_denom conn dn |> unwrap_err_caqti in
let+ () = Pg.insert_denom conn dn |> unwrap_caqti in
Logs.info (fun m ->
m "certified denomination `%s`"
(DenominationHash.to_b32 dn.h_pub));
@ -331,7 +331,7 @@ module Make (Conn : Pg.CONN) : S = struct
let* _sk = Option.to_result ~none:"signkey not found" opt in
let* () = Sm_eddsa.revoke pub in
let+ () =
Pg.insert_signkey_revocation conn pub revoked_sig |> unwrap_err_caqti
Pg.insert_signkey_revocation conn pub revoked_sig |> unwrap_caqti
in
Logs.info (fun m -> m "revoked signkey `%s`" (EddsaPublicKey.to_b32 pub));
()
@ -342,7 +342,7 @@ module Make (Conn : Pg.CONN) : S = struct
let* () = Sm_rsa.revoke dn.h_pub in
let+ () =
Pg.insert_denomination_revocation conn dn.h_pub revoked_sig
|> unwrap_err_caqti
|> unwrap_caqti
in
Logs.info (fun m ->
m "revoked denomination `%s`" (DenominationHash.to_b32 h_pub));

View file

@ -41,13 +41,11 @@ let mk_keys ~db_conn (module Keys : Keys.S) ~last_issue_date =
let stefan_lin = Config.stefan_lin in
(* type of the asset. "fiat", "crypto", "regional" or "stock". *)
let asset_type = "fiat" in
let* accounts = Pg.get_wire_accounts db_conn () |> unwrap_err_caqti in
let* accounts = Pg.get_wire_accounts db_conn () |> unwrap_caqti in
let* wire_fees =
(* wire_methods? *)
let wire_method = "x-taler-bank" in
let+ wire_fees =
Pg.get_wire_fees db_conn ~wire_method |> unwrap_err_caqti
in
let+ wire_fees = Pg.get_wire_fees db_conn ~wire_method |> unwrap_caqti in
String_map.singleton wire_method wire_fees
in
let wads = [] in
@ -111,7 +109,7 @@ let mk_keys ~db_conn (module Keys : Keys.S) ~last_issue_date =
let recoup = (* /recoup *) [] in
let* global_fees =
Pg.get_global_fees db_conn ~start_date:Timestamp.zero |> unwrap_err_caqti
Pg.get_global_fees db_conn ~start_date:Timestamp.zero |> unwrap_caqti
in
let* auditors =
(* /auditors/$AUDITOR_PUB/$H_DENOM_PUB *)

View file

@ -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 ()
@ -114,18 +114,18 @@ module Auditors = struct
let do_ ~db_conn v =
let auditor_pub = v.AuditorSetupMessage.auditor_pub in
let validity_start = v.AuditorSetupMessage.validity_start in
let* opt = Pg.find_auditor db_conn auditor_pub |> unwrap_err_caqti in
let* opt = Pg.find_auditor db_conn auditor_pub |> unwrap_caqti in
match opt with
| None ->
let auditor = Auditor.of_setup_message v in
let+ () = Pg.update_auditor db_conn auditor |> unwrap_err_caqti in
let+ () = Pg.update_auditor db_conn auditor |> unwrap_caqti in
Logs.info (fun m -> m "enabled auditor");
()
| Some auditor ->
if Timestamp.compare validity_start auditor.last_change <= 0 then
Error "replay detected on enable-auditor"
else
let+ () = Pg.update_auditor db_conn auditor |> unwrap_err_caqti in
let+ () = Pg.update_auditor db_conn auditor |> unwrap_caqti in
Logs.info (fun m -> m "updated auditor");
()
@ -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 ()
@ -153,7 +153,7 @@ module Auditors_disable = struct
let do_ ~db_conn auditor_pub
AuditorTeardownMessage.{ master_sig= _; validity_end } =
let* opt = Pg.find_auditor db_conn auditor_pub |> unwrap_err_caqti in
let* opt = Pg.find_auditor db_conn auditor_pub |> unwrap_caqti in
match opt with
| None -> Error "auditor not found"
| Some auditor -> (
@ -168,7 +168,7 @@ module Auditors_disable = struct
let auditor =
{ auditor with last_change= validity_end; is_active= false }
in
let+ () = Pg.update_auditor db_conn auditor |> unwrap_err_caqti in
let+ () = Pg.update_auditor db_conn auditor |> unwrap_caqti in
Logs.info (fun m ->
m "revoked auditor `%s`"
(Crypto.EddsaPublicKey.to_b32 auditor_pub));
@ -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 ()
@ -215,11 +215,11 @@ module Wire_fee = struct
let* wire_fees =
Pg.get_wire_fees_by_time db_conn ~wire_method:v.wire_method
~start_date:v.fee_start ~end_date:v.fee_end
|> unwrap_err_caqti
|> unwrap_caqti
in
match wire_fees with
| [] ->
let+ () = Pg.insert_wire_fee db_conn v |> unwrap_err_caqti in
let+ () = Pg.insert_wire_fee db_conn v |> unwrap_caqti in
Logs.info (fun m -> m "added wire fee");
()
| [ vv ] -> (
@ -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 ()
@ -256,12 +256,11 @@ module Global_fees = struct
let* global_fees =
let start_date = v.GlobalFees.start_date in
let end_date = v.GlobalFees.end_date in
Pg.get_global_fees_by_time db_conn ~start_date ~end_date
|> unwrap_err_caqti
Pg.get_global_fees_by_time db_conn ~start_date ~end_date |> unwrap_caqti
in
match global_fees with
| [] ->
let+ () = Pg.insert_global_fees db_conn v |> unwrap_err_caqti in
let+ () = Pg.insert_global_fees db_conn v |> unwrap_caqti in
Logs.info (fun m -> m "added global fees");
()
| [ vv ] -> (
@ -287,7 +286,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 ()
@ -362,7 +361,7 @@ module Wire = struct
bank_label;
priority;
} =
let* opt = Pg.find_wire db_conn ~payto_uri |> unwrap_err_caqti in
let* opt = Pg.find_wire db_conn ~payto_uri |> unwrap_caqti in
match opt with
| None ->
let wire =
@ -380,7 +379,7 @@ module Wire = struct
let+ () =
Pg.update_wire db_conn ~is_active:true ~last_change:validity_start
wire
|> unwrap_err_caqti
|> unwrap_caqti
in
Logs.info (fun m -> m "added wire method");
()
@ -391,7 +390,7 @@ module Wire = struct
let+ () =
Pg.update_wire db_conn ~is_active:true ~last_change:validity_start
wire
|> unwrap_err_caqti
|> unwrap_caqti
in
Logs.info (fun m -> m "updated wire method");
()
@ -403,7 +402,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 ()
@ -420,7 +419,7 @@ module Wire_disable = struct
let do_ ~db_conn
WireTeardownMessage.{ payto_uri; master_sig_del= _; validity_end } =
let* opt = Pg.find_wire db_conn ~payto_uri |> unwrap_err_caqti in
let* opt = Pg.find_wire db_conn ~payto_uri |> unwrap_caqti in
match opt with
| None -> Error "wire not found"
| Some (wire, _is_active, last_change) ->
@ -430,7 +429,7 @@ module Wire_disable = struct
let+ () =
Pg.update_wire db_conn ~is_active:false ~last_change:validity_end
wire
|> unwrap_err_caqti
|> unwrap_caqti
in
Logs.info (fun m -> m "disabled wire method");
()
@ -442,7 +441,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 ()
@ -473,15 +472,14 @@ module Drain = struct
let do_ ~db_conn v =
let* opt =
Pg.find_drain_profit db_conn v.DrainProfitsMessage.wtid
|> unwrap_err_caqti
Pg.find_drain_profit db_conn v.DrainProfitsMessage.wtid |> unwrap_caqti
in
match opt with
| Some _ ->
Logs.info (fun m -> m "drain profit message already added to database");
Ok ()
| None ->
let+ () = Pg.insert_drain_profit db_conn v |> unwrap_err_caqti in
let+ () = Pg.insert_drain_profit db_conn v |> unwrap_caqti in
Logs.info (fun m -> m "added drain profit message to database");
()
@ -492,7 +490,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 ()
@ -522,7 +520,7 @@ module AmlOfficer = struct
}
let do_ ~db_conn v =
let+ _last_change = Pg.insert_aml_officer db_conn v |> unwrap_err_caqti in
let+ _last_change = Pg.insert_aml_officer db_conn v |> unwrap_caqti in
()
let jsont = AmlOfficerSetup.jsont
@ -532,7 +530,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 ()
@ -564,7 +562,7 @@ module Partners = struct
}
let do_ ~db_conn v =
let+ () = Pg.insert_partner db_conn v |> unwrap_err_caqti in
let+ () = Pg.insert_partner db_conn v |> unwrap_caqti in
()
let jsont = ExchangePartnerSetupRequest.jsont
@ -574,7 +572,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 ()

View file

@ -157,7 +157,7 @@ let get_auditor_keys =
in
fun (module Conn : CONN) ->
let open Syntax in
let* l = Conn.collect_list req () |> unwrap_err_caqti in
let* l = Conn.collect_list req () |> unwrap_caqti in
let ht = Hashtbl.create 0xff in
List.iter
(fun (pub, url, name, denom_pub_h, auditor_sig) ->

View file

@ -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

View file

@ -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

View file

@ -5,9 +5,9 @@ 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 =
let unwrap_caqti o =
match o with Error err -> Fmt.error "%a" Caqti_error.pp err | Ok v -> Ok v
let list_iter f l =

View file

@ -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

View file

@ -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 ();