wip purpose sizeof
This commit is contained in:
parent
6ef34b8fe7
commit
e5045c2e52
2 changed files with 40 additions and 7 deletions
|
|
@ -55,27 +55,38 @@ module Hash_code = struct
|
||||||
(* usually SHA-512 *)
|
(* usually SHA-512 *)
|
||||||
type t = { hash: string (* = uint8_t hash[64] *) }
|
type t = { hash: string (* = uint8_t hash[64] *) }
|
||||||
|
|
||||||
|
let size = 64
|
||||||
|
|
||||||
let bin =
|
let bin =
|
||||||
let open Bin in
|
let open Bin in
|
||||||
record (fun hash -> { hash }) |+ field (bytes 64) (fun t -> t.hash) |> sealr
|
record (fun hash -> { hash })
|
||||||
|
|+ field (bytes size) (fun t -> t.hash)
|
||||||
|
|> sealr
|
||||||
end
|
end
|
||||||
|
|
||||||
module Short_hash_code = struct
|
module Short_hash_code = struct
|
||||||
type t = { hash: string }
|
type t = { hash: string }
|
||||||
|
|
||||||
|
let size = 32
|
||||||
|
|
||||||
let bin =
|
let bin =
|
||||||
let open Bin in
|
let open Bin in
|
||||||
record (fun hash -> { hash }) |+ field (bytes 32) (fun t -> t.hash) |> sealr
|
record (fun hash -> { hash })
|
||||||
|
|+ field (bytes size) (fun t -> t.hash)
|
||||||
|
|> sealr
|
||||||
end
|
end
|
||||||
|
|
||||||
module MAKE_H (H : sig
|
module MAKE_H (H : sig
|
||||||
type t
|
type t = { hash: string }
|
||||||
|
|
||||||
|
val size : int
|
||||||
val bin : t Bin.t
|
val bin : t Bin.t
|
||||||
end) =
|
end) =
|
||||||
struct
|
struct
|
||||||
type t = { hash: H.t }
|
type t = { hash: H.t }
|
||||||
|
|
||||||
|
let size = H.size
|
||||||
|
|
||||||
let bin =
|
let bin =
|
||||||
let open Bin in
|
let open Bin in
|
||||||
record (fun hash -> { hash }) |+ field H.bin (fun t -> t.hash) |> sealr
|
record (fun hash -> { hash }) |+ field H.bin (fun t -> t.hash) |> sealr
|
||||||
|
|
@ -279,6 +290,8 @@ module Ecc_signature_purpose = struct
|
||||||
|+ field beint32 (fun t -> t.size)
|
|+ field beint32 (fun t -> t.size)
|
||||||
|+ field beint32 (fun t -> t.purpose)
|
|+ field beint32 (fun t -> t.purpose)
|
||||||
|> sealr
|
|> sealr
|
||||||
|
|
||||||
|
let size = 4 + 4
|
||||||
end
|
end
|
||||||
|
|
||||||
(* This is the running SHA512-hash over all
|
(* This is the running SHA512-hash over all
|
||||||
|
|
@ -473,7 +486,7 @@ module Withdraw_confirmation_ps = struct
|
||||||
type t = {
|
type t = {
|
||||||
(* Purpose is #TALER_SIGNATURE_EXCHANGE_CONFIRM_WITHDRAW.
|
(* Purpose is #TALER_SIGNATURE_EXCHANGE_CONFIRM_WITHDRAW.
|
||||||
Signed by a `struct TALER_ExchangePrivateKeyP` using EdDSA. *)
|
Signed by a `struct TALER_ExchangePrivateKeyP` using EdDSA. *)
|
||||||
purpose: Ecc_signature_purpose.t;
|
(*purpose: Ecc_signature_purpose.t;*)
|
||||||
(* Commitment made in the /withdraw request.
|
(* Commitment made in the /withdraw request.
|
||||||
Also needed for the /reveal-withdraw endpoint (in case
|
Also needed for the /reveal-withdraw endpoint (in case
|
||||||
of required proof of age restriction) and for /recoup *)
|
of required proof of age restriction) and for /recoup *)
|
||||||
|
|
@ -489,11 +502,20 @@ module Withdraw_confirmation_ps = struct
|
||||||
noreveal_index: int32;
|
noreveal_index: int32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let size = Ecc_signature_purpose.size + Hash_planchets_p.size + 4
|
||||||
|
|
||||||
|
let purpose =
|
||||||
|
Ecc_signature_purpose.
|
||||||
|
{
|
||||||
|
size= Int32.of_int size;
|
||||||
|
purpose= Include.Taler_signatures.exchange_confirm_withdraw;
|
||||||
|
}
|
||||||
|
|
||||||
let bin =
|
let bin =
|
||||||
let open Bin in
|
let open Bin in
|
||||||
record (fun purpose h_planchets noreveal_index ->
|
record (fun _purpose h_planchets noreveal_index ->
|
||||||
{ purpose; h_planchets; noreveal_index })
|
{ h_planchets; noreveal_index })
|
||||||
|+ field Ecc_signature_purpose.bin (fun t -> t.purpose)
|
|+ field Ecc_signature_purpose.bin (Fun.const purpose)
|
||||||
|+ field Hash_planchets_p.bin (fun t -> t.h_planchets)
|
|+ field Hash_planchets_p.bin (fun t -> t.h_planchets)
|
||||||
|+ field beint32 (fun t -> t.noreveal_index)
|
|+ field beint32 (fun t -> t.noreveal_index)
|
||||||
|> sealr
|
|> sealr
|
||||||
|
|
|
||||||
11
test/test.ml
11
test/test.ml
|
|
@ -71,3 +71,14 @@ let () =
|
||||||
check_bad "\"foo\" ,";
|
check_bad "\"foo\" ,";
|
||||||
check_bad ", \"foo\"";
|
check_bad ", \"foo\"";
|
||||||
()
|
()
|
||||||
|
|
||||||
|
let () =
|
||||||
|
let open Binary_formats.Withdraw_confirmation_ps in
|
||||||
|
let str64 = String.make 64 '0' in
|
||||||
|
let dummy_t =
|
||||||
|
{ h_planchets= { hash= { hash= str64 } }; noreveal_index= 0_l }
|
||||||
|
in
|
||||||
|
let size' = Bin.size_of_value bin dummy_t |> Option.get in
|
||||||
|
assert (size = size');
|
||||||
|
assert (size = 76);
|
||||||
|
()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue