mte/src/bin_type.ml
2026-02-05 18:05:52 +01:00

102 lines
2.6 KiB
OCaml

(* https://docs.taler.net/core/api-common.html#binary-formats
numeric values are in network byte order (big endian) *)
(* structs that are 'packed' and do not contain pointers and are
thus suitable for hashing or similar operations are distinguished
by adding a 'P' at the end of the name.
(NEW) Note that this convention does not hold for the GNUnet-structs (yet).
structs that are used with a purpose for signatures,
additionally get an 'S' at the end of the name.
(from https://docs.taler.net/taler-developer-manual.html) *)
(* TODO
- correctly handle endianness
- check that our struct are well packed
- it looks like Bin only define packed structs
- we don't need to worry about struct having "P" suffix
remove them
- test them
- union: not sure what to do of them
not needed or relevant i think
- some purpose (`TALER_SIGNATURE_XXX`) are missing
- exchange and gana master branch are not in sync
and we should use a specific git tag instead
- outdated doc(?)
- some missing struct documentation
- better way to have module aliases?
*)
module Taler_signatures = Include.Taler_signatures
let int32_size = 4
let int64_size = 8
module Bytes_32 = struct
type t = string
let bin = Bin.bytes 32
end
module Bytes_64 = struct
type t = string
let bin = Bin.bytes 64
end
(* -- Cryptographic primitives -- *)
(* --- Various --- *)
module TransferSecretP = Bytes_64
module LinkSecretP = Bytes_64
module EncryptedLinkSecretP = Bytes_64
module BlindingMasterSeed = Bytes_32
module BlindingMasterSecret = Bytes_32
module WireTransferIdentifierRawP = Bytes_32
module PublicRefreshCoinNonceP = Bytes_64
(* TODO ? need to use/save a specific nonce for cryptographic blinding *)
(* Secret for blinding/unblinding.
An RSA blinding secret, which is basically
a 256-bit nonce, converted to Crockford `Base32`.
type DenominationBlindingKeyP = string; *)
module DenominationBlindingKeyP = Bytes_32
module RefreshCommitmentP = Bytes_64
(* -- TODO better: -- *)
module UUID = struct
(* uint32t value[4]; *)
type t = { value: string }
let size = 4 * int32_size
let bin =
let open Bin in
record (fun value -> { value })
|+ field (bytes size) (fun t -> t.value)
|> sealr
end
module WadId = struct
(* uint32t value[6]; *)
type t = { raw: string }
let size = 6 * int32_size
let bin =
let open Bin in
record (fun raw -> { raw }) |+ field (bytes size) (fun t -> t.raw) |> sealr
end
module AgeMask = struct
type t = { mask: int32 }
let bin =
let open Bin in
record (fun mask -> { mask }) |+ field beint32 (fun t -> t.mask) |> sealr
end