diff --git a/src/binary_formats.ml b/src/binary_formats.ml index 88f18f80..fe66ef4e 100644 --- a/src/binary_formats.ml +++ b/src/binary_formats.ml @@ -4,7 +4,8 @@ open Include -(* TODO test *) +let int32_size = 4 +let int64_size = 8 (* -- Time -- *) @@ -13,6 +14,8 @@ module Time = struct type t = { timestamp_us: int64 } type t_nbo = { abs_value_us__: int64 } + let size = int64_size + (* not BE here? never used? *) let bin = let open Bin in @@ -31,6 +34,8 @@ module Time = struct type t = { timestamp_us: int64 } type t_nbo = { rel_value_us__: int64 } + let size = int64_size + let bin = let open Bin in record (fun timestamp_us -> { timestamp_us }) @@ -142,24 +147,18 @@ module Exchange_signature_p = MK_64 () module Master_public_key_p = MK_32 () module Master_private_key_p = MK_32 () module Master_signature_p = MK_64 () - -module Wire_transfert_identifier_raw_p = struct - (* uint8_t raw[32]; *) - type t = { raw: string } - - let bin = - let open Bin in - record (fun raw -> { raw }) |+ field (bytes 32) (fun t -> t.raw) |> sealr -end +module Wire_transfert_identifier_raw_p = MK_BASIC_32 () module UUID = struct (* uint32_t value[4]; *) type t = { value: string } + let size = 4 * int32_size + let bin = let open Bin in record (fun value -> { value }) - |+ field (bytes (4 * 4)) (fun t -> t.value) + |+ field (bytes size) (fun t -> t.value) |> sealr end @@ -167,11 +166,11 @@ module Wad_id = struct (* uint32_t value[6]; *) type t = { raw: string } + let size = 6 * int32_size + let bin = let open Bin in - record (fun raw -> { raw }) - |+ field (bytes (4 * 6)) (fun t -> t.raw) - |> sealr + record (fun raw -> { raw }) |+ field (bytes size) (fun t -> t.raw) |> sealr end (* TODO not sure what to do of union, probably not needed *) @@ -227,7 +226,7 @@ module Purpose = struct purpose: int32; } - let size = 4 + 4 + let size = 2 * int32_size let bin = let open Bin in @@ -261,6 +260,8 @@ module Hash_planchets_p = MK_64 () module Age_mask = struct type t = { mask: int32 } + let size = int32_size + let bin = let open Bin in record (fun mask -> { mask }) |+ field beint32 (fun t -> t.mask) |> sealr @@ -331,6 +332,8 @@ module Amount = struct currency: string; } + let size = int64_size + int32_size + currency_len + (* TODO BE here? *) let bin = let open Bin in @@ -348,6 +351,8 @@ module AmountNBO = struct currency: string; } + let size = int64_size + int32_size + currency_len + let bin = let open Bin in record (fun value fraction currency -> { value; fraction; currency }) @@ -357,6 +362,8 @@ module AmountNBO = struct |> sealr end +module Blinding_master_seed = MK_BASIC_32 () + (* Format used for to generate the signature on a request to withdraw coins from a reserve. *) module Withdraw_request_ps = struct @@ -390,7 +397,7 @@ module Withdraw_request_ps = struct or all zeros, if no denomination of cipher type Clause-Schnorr is used. *) (* TODO TALER doc `TALER_BlindingMasterSecretP` in doc, but probably TALER_BlindingMasterSeed *) - blinding_seed: string; + blinding_seed: Blinding_master_seed.t; (* If age restriction proof is required, the maximum age _group_ to commit to, 0 otherwise. Note that in this case, all denominations for all coins MUST support age restriction. @@ -404,6 +411,14 @@ module Withdraw_request_ps = struct mask: Age_mask.t; } + let size = + Purpose.size + + (2 * Amount.size) + + Hash_planchets_p.size + + Blinding_master_seed.size + + int32_size + + Age_mask.size + let bin = let open Bin in record @@ -421,7 +436,7 @@ module Withdraw_request_ps = struct |+ field Amount.bin (fun t -> t.amount) |+ field Amount.bin (fun t -> t.fee) |+ field Hash_planchets_p.bin (fun t -> t.h_planchets) - |+ field cstring (fun t -> t.blinding_seed) + |+ field Blinding_master_seed.bin (fun t -> t.blinding_seed) |+ field beint32 (fun t -> t.max_age_group) |+ field Age_mask.bin (fun t -> t.mask) |> sealr @@ -446,7 +461,7 @@ module Withdraw_confirmation_ps = struct noreveal_index: int32; } - let size = Purpose.size + Hash_planchets_p.size + 4 + let size = Purpose.size + Hash_planchets_p.size + int32_size let purpose = Purpose.make size Taler_signatures.exchange_confirm_withdraw let bin =