From 56694e9b3ed43de1af48fecbb10a535814aa90f7 Mon Sep 17 00:00:00 2001 From: swrup Date: Sat, 18 Oct 2025 14:55:16 +0200 Subject: [PATCH] --- src/binary_formats.ml | 99 +++++++++++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 36 deletions(-) diff --git a/src/binary_formats.ml b/src/binary_formats.ml index c0bbb70e..83cb48c9 100644 --- a/src/binary_formats.ml +++ b/src/binary_formats.ml @@ -41,29 +41,38 @@ let int32_size = 4 let int64_size = 8 +(* -- Time -- *) + +(* microseconds since the UNIX Epoch + UINT64_MAX represents "never" *) +module MK_TIME () = struct + type t = { v: int64 } + + (* not BE (?) *) + let bin = + let open Bin in + record (fun v -> { v }) |+ field neint64 (fun t -> t.v) |> sealr +end + +module MK_TIME_NBO () = struct + type t = { v: int64 } + + let bin = + let open Bin in + record (fun v -> { v }) |+ field beint64 (fun t -> t.v) |> sealr +end + +module TimeAbsolute = MK_TIME () +module TimeAbsoluteNBO = MK_TIME_NBO () +module TimeRelative = MK_TIME () +module TimeRelativeNBO = MK_TIME_NBO () +module Timestamp = MK_TIME () +module TimestampNBO = MK_TIME_NBO () + (* TODO clean up ? rm all of UTIL ? Bin.map int64 to Ptime.t here *) module UTIL = struct - (* microseconds since the UNIX Epoch - UINT64_MAX represents "never" *) - module MK_TIME () = struct - type t = { v: int64 } - - (* not BE (?) *) - let bin = - let open Bin in - record (fun v -> { v }) |+ field neint64 (fun t -> t.v) |> sealr - end - - module MK_TIME_NBO () = struct - type t = { v: int64 } - - let bin = - let open Bin in - record (fun v -> { v }) |+ field beint64 (fun t -> t.v) |> sealr - end - module type Bytes_sig = sig type t = { v: string } @@ -196,20 +205,41 @@ module UTIL = struct module MK_HASH_32 () : H_sig = struct include HHH_32 end + + module MK_SRC_HASH_64 (M : sig + type src + + val to_octets : src -> string + end) : sig + type t + + val bin : t Bin.t + val hash : M.src -> t + end = struct + include Hash_64 + + let hash src = hash (M.to_octets src) + end + + module MK_SRC_HASH_32 (M : sig + type src + + val to_octets : src -> string + end) : sig + type t + + val bin : t Bin.t + val hash : M.src -> t + end = struct + include Hash_32 + + let hash src = hash (M.to_octets src) + end end include UTIL module Taler_signatures = Include.Taler_signatures -(* -- Time -- *) - -module TimeAbsolute = MK_TIME () -module TimeAbsoluteNBO = MK_TIME_NBO () -module TimeRelative = MK_TIME () -module TimeRelativeNBO = MK_TIME_NBO () -module Timestamp = MK_TIME () -module TimestampNBO = MK_TIME_NBO () - (* -- Cryptographic primitives -- *) (* GNUNET_CRYPTO format *) @@ -274,15 +304,12 @@ module GNUNET_RsaPublicKey = struct t end -module DenominationHash = struct - include Hash_64 +module DenominationHash = MK_SRC_HASH_32 (struct + type src = Mirage_crypto_pk.Rsa.pub - let hash (pub : Mirage_crypto_pk.Rsa.pub) = - pub - |> GNUNET_RsaPublicKey.of_pub - |> Bin.to_string GNUNET_RsaPublicKey.bin - |> hash -end + let to_octets pub = + GNUNET_RsaPublicKey.of_pub pub |> Bin.to_string GNUNET_RsaPublicKey.bin +end) module ExchangePublicKeyP = struct type t = Mirage_crypto_ec.Ed25519.pub