From 454090546f009310409653533d53296c363818eb Mon Sep 17 00:00:00 2001 From: swrup Date: Tue, 7 Oct 2025 12:02:16 +0200 Subject: [PATCH] purpose rec sizeof --- src/binary_formats.ml | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/binary_formats.ml b/src/binary_formats.ml index fd9cafe2..6d42bd03 100644 --- a/src/binary_formats.ml +++ b/src/binary_formats.ml @@ -55,27 +55,38 @@ module Hash_code = struct (* usually SHA-512 *) type t = { hash: string (* = uint8_t hash[64] *) } + let size = 64 + let bin = let open Bin in - record (fun hash -> { hash }) |+ field (bytes 64) (fun t -> t.hash) |> sealr + record (fun hash -> { hash }) + |+ field (bytes size) (fun t -> t.hash) + |> sealr end module Short_hash_code = struct type t = { hash: string } + let size = 32 + let bin = let open Bin in - record (fun hash -> { hash }) |+ field (bytes 32) (fun t -> t.hash) |> sealr + record (fun hash -> { hash }) + |+ field (bytes size) (fun t -> t.hash) + |> sealr end module MAKE_H (H : sig - type t + type t = { hash: string } + val size : int val bin : t Bin.t end) = struct type t = { hash: H.t } + let size = H.size + let bin = let open Bin in record (fun hash -> { hash }) |+ field H.bin (fun t -> t.hash) |> sealr @@ -279,6 +290,8 @@ module Ecc_signature_purpose = struct |+ field beint32 (fun t -> t.size) |+ field beint32 (fun t -> t.purpose) |> sealr + + let size = 4 + 4 end (* This is the running SHA512-hash over all @@ -473,7 +486,7 @@ module Withdraw_confirmation_ps = struct type t = { (* Purpose is #TALER_SIGNATURE_EXCHANGE_CONFIRM_WITHDRAW. Signed by a `struct TALER_ExchangePrivateKeyP` using EdDSA. *) - purpose: Ecc_signature_purpose.t; + (*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 *) @@ -489,11 +502,20 @@ 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 bin = let open Bin in - record (fun purpose h_planchets noreveal_index -> - { purpose; h_planchets; noreveal_index }) - |+ field Ecc_signature_purpose.bin (fun t -> t.purpose) + record (fun _purpose h_planchets noreveal_index -> + { h_planchets; noreveal_index }) + |+ field Ecc_signature_purpose.bin (Fun.const purpose) |+ field Hash_planchets_p.bin (fun t -> t.h_planchets) |+ field beint32 (fun t -> t.noreveal_index) |> sealr