purpose rec sizeof

This commit is contained in:
swrup 2025-10-07 12:02:16 +02:00
parent 6ef34b8fe7
commit 97a2e9ddf4

View file

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