From 4dcde34a4171763d12ec6f130979728809e5d95a Mon Sep 17 00:00:00 2001 From: swrup Date: Tue, 7 Oct 2025 14:59:58 +0200 Subject: [PATCH] --- src/binary_formats.ml | 174 +++++++++++++++++++++--------------------- test/test.ml | 2 +- 2 files changed, 88 insertions(+), 88 deletions(-) diff --git a/src/binary_formats.ml b/src/binary_formats.ml index 6e1e8fc2..38900c29 100644 --- a/src/binary_formats.ml +++ b/src/binary_formats.ml @@ -12,7 +12,7 @@ let int64_size = 8 module Time = struct module Absolute = struct type t = { timestamp_us: int64 } - type t_nbo = { abs_value_us__: int64 } + type tNbo = { abs_value_us__: int64 } let size = int64_size @@ -23,7 +23,7 @@ module Time = struct |+ field neint64 (fun t -> t.timestamp_us) |> sealr - let nbo_bin = + let nboBin = let open Bin in record (fun abs_value_us__ -> { abs_value_us__ }) |+ field beint64 (fun t -> t.abs_value_us__) @@ -32,7 +32,7 @@ module Time = struct module Relative = struct type t = { timestamp_us: int64 } - type t_nbo = { rel_value_us__: int64 } + type tNbo = { relValue_us__: int64 } let size = int64_size @@ -42,10 +42,10 @@ module Time = struct |+ field neint64 (fun t -> t.timestamp_us) |> sealr - let nbo_bin = + let nboBin = let open Bin in - record (fun rel_value_us__ -> { rel_value_us__ }) - |+ field beint64 (fun t -> t.rel_value_us__) + record (fun relValue_us__ -> { relValue_us__ }) + |+ field beint64 (fun t -> t.relValue_us__) |> sealr end end @@ -53,7 +53,7 @@ end (* -- Cryptographic primitives -- *) (* MK_BASIC_XX functor for structs like: - struct Foo { uint8_t bar[XX]; } *) + struct Foo { uint8T bar[XX]; } *) module MKMK_BASIC (Size : sig val v : int end) = @@ -79,7 +79,7 @@ module MK_BASIC_32 () = MKMK_BASIC (SIZE_32) module MK_BASIC_64 () = MKMK_BASIC (SIZE_64) (* MK_XX functor for structs like: - struct FooWrap { struct Foo { uint8_t bar[XX]; } } *) + struct FooWrap { struct Foo { uint8T bar[XX]; } } *) module MKMK (Size : sig val v : int end) = @@ -101,37 +101,37 @@ module MK_64 () = MKMK (SIZE_64) module ShortHashCode = MK_BASIC_32 () module HashCode = MK_BASIC_64 () -module Denomination_hash = MK_64 () -module Private_contract_hash = MK_64 () -module Extensions_policy_hash = MK_64 () -module Merchant_wire_hash = MK_64 () +module DenominationHash = MK_64 () +module PrivateContractHash = MK_64 () +module ExtensionsPolicyHash = MK_64 () +module MerchantWireHash = MK_64 () (* Hash over a full payto://-URI, including receiver-name (and possibly BIC and other optional fields). *) -module Full_payto_hash = MK_32 () +module FullPaytoHash = MK_32 () (* Hash over a normalized payto://-URI, including all optional fields and also with account-part canonicalized (so no BIC). *) -module Normalized_payto_hash = MK_32 () +module NormalizedPaytoHash = MK_32 () (* Hash over: a) the hash of the denomination's public key, b) an enum value identifying the cipher, and c) cipher-dependant blinded information. - See implementation of `TALER_coin_ev_hash` + See implementation of `TALER_CoinEvHash` in libtalerexchange for details. *) -module Blinded_coin_hash = MK_64 () -module Coin_pub_hash = MK_64 () -module Output_commitment_hash = MK_64 () -module Reserve_public_key_p = MK_32 () -module Reserve_private_key_p = MK_32 () -module Reserve_signature_p = MK_64 () -module Merchant_public_key_p = MK_32 () -module Merchant_private_key_p = MK_32 () -(*module Merchant_signature_p = MK_64 () *) +module BlindedCoinHash = MK_64 () +module CoinPubHash = MK_64 () +module OutputCommitmentHash = MK_64 () +module ReservePublicKeyP = MK_32 () +module ReservePrivateKeyP = MK_32 () +module ReserveSignatureP = MK_64 () +module MerchantPublicKeyP = MK_32 () +module MerchantPrivateKeyP = MK_32 () +(*module MerchantSignatureP = MK_64 () *) -module Transfert_public_key_p = MK_32 () -module Transfert_private_key_p = MK_32 () +module TransfertPublicKeyP = MK_32 () +module TransfertPrivateKeyP = MK_32 () (* enum TALER_AmlDecisionState { @@ -139,18 +139,18 @@ enum TALER_AmlDecisionState { }; *) -module Aml_officer_public_key_p = MK_32 () -module Aml_officer_private_key_p = MK_32 () -module Exchange_public_key_p = MK_32 () -module Exchange_private_key_p = MK_32 () -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 = MK_BASIC_32 () +module AmlOfficerPublicKeyP = MK_32 () +module AmlOfficerPrivateKeyP = MK_32 () +module ExchangePublicKeyP = MK_32 () +module ExchangePrivateKeyP = MK_32 () +module ExchangeSignatureP = MK_64 () +module MasterPublicKeyP = MK_32 () +module MasterPrivateKeyP = MK_32 () +module MasterSignatureP = MK_64 () +module WireTransfertIdentifierRawP = MK_BASIC_32 () module UUID = struct - (* uint32_t value[4]; *) + (* uint32t value[4]; *) type t = { value: string } let size = 4 * int32_size @@ -162,8 +162,8 @@ module UUID = struct |> sealr end -module Wad_id = struct - (* uint32_t value[6]; *) +module WadId = struct + (* uint32t value[6]; *) type t = { raw: string } let size = 6 * int32_size @@ -176,40 +176,40 @@ end (* TODO not sure what to do of union, probably not needed *) (* union TALER_CoinSpendPublicKeyP { - uint8_t eddsa_pub[32]; - uint8_t ecdhe_pub[32]; + uint8T eddsaPub[32]; + uint8T ecdhePub[32]; }; union TALER_CoinSpendPrivateKeyP { - uint8_t eddsa_priv[32]; - uint8_t ecdhe_priv[32]; + uint8T eddsaPriv[32]; + uint8T ecdhePriv[32]; }; *) -module Coin_spend_public_key_p = MK_32 () -module Coin_spend_private_key_p = MK_32 () -module Coin_spend_signature_p = MK_64 () +module CoinSpendPublicKeyP = MK_32 () +module CoinSpendPrivateKeyP = MK_32 () +module CoinSpendSignatureP = MK_64 () (* TODO padding: sizeof used here (assume no padding for now) *) (* struct TALER_TransferSecretP { - uint8_t key[sizeof (struct GNUNET_HashCode)]; + uint8T key[sizeof (struct GNUNET_HashCode)]; }; - uint8_t key[sizeof (struct GNUNET_HashCode)]; + uint8T key[sizeof (struct GNUNET_HashCode)]; }; struct TALER_EncryptedLinkSecretP { - uint8_t enc[sizeof (struct TALER_LinkSecretP)]; + uint8T enc[sizeof (struct TALER_LinkSecretP)]; }; *) -module Transfert_secret_p = MK_64 () -module Link_secret_p = MK_64 () -module Encrypted_link_secret_p = MK_64 () +module TransfertSecretP = MK_64 () +module LinkSecretP = MK_64 () +module EncryptedLinkSecretP = MK_64 () (* union TALER_TokenPublicKeyP { - uint8_t eddsa_pub[32]; - uint8_t ecdhe_pub[32]; + uint8T eddsaPub[32]; + uint8T ecdhePub[32]; }; *) -module Token_public_key_p = MK_32 () +module TokenPublicKeyP = MK_32 () (* -- Signatures -- *) @@ -243,7 +243,7 @@ end Note that each `TALER_BlindedCoinHashP` itself captures the hash of the corresponding denomination's public key. *) -module Hash_planchets_p = MK_64 () +module HashPlanchetsP = MK_64 () (* Binary representation of the age groups. The bits set in the mask mark the edges at the beginning of a next age @@ -257,7 +257,7 @@ module Hash_planchets_p = MK_64 () A value of 0 means that the exchange does not support the extension for age-restriction. *) -module Age_mask = struct +module AgeMask = struct type t = { mask: int32 } let size = int32_size @@ -269,7 +269,7 @@ end (* TODO TALER doc should be in doc - found in src/include/taler/taler_amount_lib.h + found in src/include/taler/talerAmountLib.h why is the non-NBO version only used in TALER_WithdrawRequestPS? GNUNET_PACKED? @@ -291,12 +291,12 @@ struct TALER_AmountNBO /** * Value in the main currency, in NBO. */ - uint64_t value GNUNET_PACKED; + uint64T value GNUNET_PACKED; /** * Fraction (integer multiples of #TALER_AMOUNT_FRAC_BASE), in NBO. */ - uint32_t fraction GNUNET_PACKED; + uint32T fraction GNUNET_PACKED; /** * Type of the currency being represented. @@ -309,12 +309,12 @@ struct TALER_Amount /** * Value (numerator of fraction) */ - uint64_t value; + uint64T value; /** * Fraction (integer multiples of #TALER_AMOUNT_FRAC_BASE). */ - uint32_t fraction; + uint32T fraction; /** * Currency string, left adjusted and padded with zeros. All zeros @@ -323,7 +323,7 @@ struct TALER_Amount char currency[TALER_CURRENCY_LEN]; }; *) -let currency_len = 12 +let currencyLen = 12 module Amount = struct type t = { @@ -332,7 +332,7 @@ module Amount = struct currency: string; } - let size = int64_size + int32_size + currency_len + let size = int64_size + int32_size + currencyLen (* TODO BE here? *) let bin = @@ -340,7 +340,7 @@ module Amount = struct record (fun value fraction currency -> { value; fraction; currency }) |+ field beint64 (fun t -> t.value) |+ field beint32 (fun t -> t.fraction) - |+ field (bytes currency_len) (fun t -> t.currency) + |+ field (bytes currencyLen) (fun t -> t.currency) |> sealr end @@ -351,22 +351,22 @@ module AmountNBO = struct currency: string; } - let size = int64_size + int32_size + currency_len + let size = int64_size + int32_size + currencyLen let bin = let open Bin in record (fun value fraction currency -> { value; fraction; currency }) |+ field beint64 (fun t -> t.value) |+ field beint32 (fun t -> t.fraction) - |+ field (bytes currency_len) (fun t -> t.currency) + |+ field (bytes currencyLen) (fun t -> t.currency) |> sealr end -module Blinding_master_seed = MK_BASIC_32 () +module BlindingMasterSeed = MK_BASIC_32 () (* Format used for to generate the signature on a request to withdraw coins from a reserve. *) -module Withdraw_request_ps = struct +module WithdrawRequestPs = struct (* Purpose is #TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW *) type t = { (* Amount to withdraw, excluding fees, i.e. @@ -381,7 +381,7 @@ module Withdraw_request_ps = struct Note that each `TALER_BlindedCoinHashP` itself captures the hash of the corresponding denomination's public key. - If max_age was set in the withdraw request, there will be + If maxAge was set in the withdraw request, there will be n*κ many such values. The iteration MUST be first over all coins belonging to κ index=0, then all coins to κ index=1 etc: @@ -390,51 +390,51 @@ module Withdraw_request_ps = struct Note also that this value is required for /recoup and -- in case of a withdraw request with required age proof -- in the subsequent call to /reveal-withdraw *) - h_planchets: Hash_planchets_p.t; + h_planchets: HashPlanchetsP.t; (* The master seed that was used in the call to /blinding-prepare blinding, 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: Blinding_master_seed.t; - (* If age restriction proof is required, the maximum age _group_ + blinding_seed: BlindingMasterSeed.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. Also note that this is not an age (in years), but the age group (an index) according to list of age groups in the configuration - of the exchange. See TALER_get_max_group() how to calculate + of the exchange. See TALER_GetMaxGroup() how to calculate the age group to a given age (in years). *) max_age_group: int32; (* The age groups as configured for the exchange, represented as a mask. If max_age_group is > 0, the mask MUST be non-zero, too. *) - mask: Age_mask.t; + mask: AgeMask.t; } let size = Purpose.size + (2 * Amount.size) - + Hash_planchets_p.size - + Blinding_master_seed.size + + HashPlanchetsP.size + + BlindingMasterSeed.size + int32_size - + Age_mask.size + + AgeMask.size let purpose = Purpose.make ~size Taler_signatures.wallet_reserve_withdraw let bin = let open Bin in record - (fun _purpose amount fee h_planchets blinding_seed max_age_group mask -> + (fun _urpose amount fee h_planchets blinding_seed max_age_group mask -> { amount; fee; h_planchets; blinding_seed; max_age_group; mask }) |+ field Purpose.bin (Fun.const 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) - |+ field Blinding_master_seed.bin (fun t -> t.blinding_seed) + |+ field HashPlanchetsP.bin (fun t -> t.h_planchets) + |+ field BlindingMasterSeed.bin (fun t -> t.blinding_seed) |+ field beint32 (fun t -> t.max_age_group) - |+ field Age_mask.bin (fun t -> t.mask) + |+ field AgeMask.bin (fun t -> t.mask) |> sealr end -module Withdraw_confirmation_ps = struct +module WithdrawConfirmationPs = struct (* Purpose is #TALER_SIGNATURE_EXCHANGE_CONFIRM_WITHDRAW. Signed by a `struct TALER_ExchangePrivateKeyP` using EdDSA. *) type t = { @@ -443,9 +443,9 @@ module Withdraw_confirmation_ps = struct of required proof of age restriction) and for /recoup *) (* TODO TALER doc missing TALER_HashBlindedPlanchetsP*) - h_planchets: Hash_planchets_p.t; + h_planchets: HashPlanchetsP.t; (* If proof of age restriction is not required for to this - withdrawal, (i.e. max_age was not set during the request) + withdrawal, (i.e. maxAge was not set during the request) MUST be 0xFFFFFFFF. Otherwise (i.e. proof of age restriction required): index that the client will not have to reveal, in NBO, @@ -453,15 +453,15 @@ module Withdraw_confirmation_ps = struct noreveal_index: int32; } - let size = Purpose.size + Hash_planchets_p.size + int32_size + let size = Purpose.size + HashPlanchetsP.size + int32_size let purpose = Purpose.make ~size Taler_signatures.exchange_confirm_withdraw let bin = let open Bin in - record (fun _purpose h_planchets noreveal_index -> + record (fun _urpose h_planchets noreveal_index -> { h_planchets; noreveal_index }) |+ field Purpose.bin (Fun.const purpose) - |+ field Hash_planchets_p.bin (fun t -> t.h_planchets) + |+ field HashPlanchetsP.bin (fun t -> t.h_planchets) |+ field beint32 (fun t -> t.noreveal_index) |> sealr end diff --git a/test/test.ml b/test/test.ml index d84044b2..0d8d4ed2 100644 --- a/test/test.ml +++ b/test/test.ml @@ -73,7 +73,7 @@ let () = () let () = - let open Binary_formats.Withdraw_confirmation_ps in + let open Binary_formats.WithdrawConfirmationPs in let str64 = String.make 64 '0' in let dummy_t = { h_planchets= { v= { v= str64 } }; noreveal_index= 0_l } in let size' = Bin.size_of_value bin dummy_t |> Option.get in