diff --git a/src/binary_formats.ml b/src/binary_formats.ml index 6d42bd03..d833311f 100644 --- a/src/binary_formats.ml +++ b/src/binary_formats.ml @@ -2,6 +2,8 @@ - numeric values are in network byte order (big endian) *) +open Include + (* TODO less boilerplate? - type t abstract @@ -272,7 +274,8 @@ module Token_public_key_p = MAKE_EDDSA_PUB () (* -- Signatures -- *) -module Ecc_signature_purpose = struct +(* EccSignaturePurpose *) +module Purpose = struct type t = { (* This field equals the number of bytes being signed, namely 'sizeof (struct Data)'. *) @@ -284,6 +287,8 @@ module Ecc_signature_purpose = struct purpose: int32; } + let size = 4 + 4 + let bin = let open Bin in record (fun size purpose -> { size; purpose }) @@ -291,7 +296,7 @@ module Ecc_signature_purpose = struct |+ field beint32 (fun t -> t.purpose) |> sealr - let size = 4 + 4 + let make size purpose = { size= Int32.of_int size; purpose } end (* This is the running SHA512-hash over all @@ -418,7 +423,7 @@ module Withdraw_request_ps = struct type t = { (* TODO set it in encode/decode *) (* Purpose is #TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW *) - purpose: Ecc_signature_purpose.t; + purpose: Purpose.t; (* Amount to withdraw, excluding fees, i.e. the total sum of the denominations of the coins. Note that the reserve must have a value of at least amount+fee. *) @@ -472,7 +477,7 @@ module Withdraw_request_ps = struct max_age_group; mask; }) - |+ field Ecc_signature_purpose.bin (fun t -> t.purpose) + |+ field Purpose.bin (fun t -> t.purpose) |+ field Amount.bin (fun t -> t.amount) |+ field Amount.bin (fun t -> t.fee) |+ field Hash_planchets_p.bin (fun t -> t.h_planchets) @@ -483,10 +488,9 @@ module Withdraw_request_ps = struct end module Withdraw_confirmation_ps = struct + (* Purpose is #TALER_SIGNATURE_EXCHANGE_CONFIRM_WITHDRAW. + Signed by a `struct TALER_ExchangePrivateKeyP` using EdDSA. *) type t = { - (* Purpose is #TALER_SIGNATURE_EXCHANGE_CONFIRM_WITHDRAW. - Signed by a `struct TALER_ExchangePrivateKeyP` using EdDSA. *) - (*purpose: Ecc_signature_purpose.t;*) (* Commitment made in the /withdraw request. Also needed for the /reveal-withdraw endpoint (in case of required proof of age restriction) and for /recoup *) @@ -502,20 +506,14 @@ module Withdraw_confirmation_ps = struct noreveal_index: int32; } - let size = Ecc_signature_purpose.size + Hash_planchets_p.size + 4 - - let purpose = - Ecc_signature_purpose. - { - size= Int32.of_int size; - purpose= Include.Taler_signatures.exchange_confirm_withdraw; - } + let size = Purpose.size + Hash_planchets_p.size + 4 + let purpose = Purpose.make size Taler_signatures.exchange_confirm_withdraw let bin = let open Bin in record (fun _purpose h_planchets noreveal_index -> { h_planchets; noreveal_index }) - |+ field Ecc_signature_purpose.bin (Fun.const purpose) + |+ field Purpose.bin (Fun.const purpose) |+ field Hash_planchets_p.bin (fun t -> t.h_planchets) |+ field beint32 (fun t -> t.noreveal_index) |> sealr