diff --git a/include/gen_taler_signatures.ml b/include/gen_taler_signatures.ml index b7667f5b..27472b3a 100644 --- a/include/gen_taler_signatures.ml +++ b/include/gen_taler_signatures.ml @@ -42,7 +42,9 @@ let () = let l = parse Data.content in assert (List.length l = 74); - let pp ppf { name; value } = Fmt.pf ppf "let %s = %d@." name value in + let pp ppf { name; value } = + Fmt.pf ppf "let %s : int32 = %d_l@." name value + in Fmt.pr "%a" (Fmt.list pp) l; () diff --git a/src/binary_formats.ml b/src/binary_formats.ml new file mode 100644 index 00000000..35cf5531 --- /dev/null +++ b/src/binary_formats.ml @@ -0,0 +1,34 @@ +(* https://docs.taler.net/core/api-common.html#binary-formats + + - numeric values are in network byte order (big endian) *) + +module Purpose = struct + (* defined in gnunet_crypto_lib.h *) + type t = { + (* This field equals the number of bytes being signed, + namely 'sizeof (struct Data)'. *) + size: int32; (* = uint32_t *) + (* This field is used to express the context in + which the signature is made, ensuring that a + signature cannot be lifted from one part of the protocol + to another. *) + purpose: int32; (* = uint32_t *) + } + + (* TODO endianess? *) + let bin_t = + let open Bin in + record (fun size purpose -> { size; purpose }) + |+ field beint32 (fun t -> t.size) + |+ field beint32 (fun t -> t.purpose) + |> sealr + + let to_string t = Bin.to_string bin_t t +end + +module Data = struct + type t = { + purpose: Purpose.t; + payloads: string list; + } +end diff --git a/src/dune b/src/dune index d8040682..09f9cdfd 100644 --- a/src/dune +++ b/src/dune @@ -13,6 +13,7 @@ ; include ; + bin angstrom zarith ; mirage-crypto diff --git a/src/signatures.ml b/src/signatures.ml deleted file mode 100644 index 9db5dbb2..00000000 --- a/src/signatures.ml +++ /dev/null @@ -1,23 +0,0 @@ -(* https://docs.taler.net/core/api-common.html#id7 *) - -module Purpose = struct - (* defined in gnunet_crypto_lib.h *) - type t = { - (* This field equals the number of bytes being signed, - namely 'sizeof (struct Data)'. *) - size: Int32.t; (* = uint32_t *) - (* This field is used to express the context in - which the signature is made, ensuring that a - signature cannot be lifted from one part of the protocol - to another. See `src/include/taler/taler_signatures.h` within the - exchange's codebase (git://taler.net/exchange). *) - purpose: Int32.t; (* = uint32_t *) - } -end - -module Data = struct - type t = { - purpose: Purpose.t; - payloads: string list; - } -end