wip purpose sizeof
This commit is contained in:
parent
6ef34b8fe7
commit
0fef7fbd10
2 changed files with 43 additions and 12 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
- numeric values are in network byte order (big endian) *)
|
- numeric values are in network byte order (big endian) *)
|
||||||
|
|
||||||
|
open Include
|
||||||
|
|
||||||
(* TODO
|
(* TODO
|
||||||
less boilerplate?
|
less boilerplate?
|
||||||
- type t abstract
|
- type t abstract
|
||||||
|
|
@ -55,27 +57,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
|
||||||
|
|
@ -261,7 +274,8 @@ module Token_public_key_p = MAKE_EDDSA_PUB ()
|
||||||
|
|
||||||
(* -- Signatures -- *)
|
(* -- Signatures -- *)
|
||||||
|
|
||||||
module Ecc_signature_purpose = struct
|
(* EccSignaturePurpose *)
|
||||||
|
module Purpose = struct
|
||||||
type t = {
|
type t = {
|
||||||
(* This field equals the number of bytes being signed,
|
(* This field equals the number of bytes being signed,
|
||||||
namely 'sizeof (struct Data)'. *)
|
namely 'sizeof (struct Data)'. *)
|
||||||
|
|
@ -273,12 +287,16 @@ module Ecc_signature_purpose = struct
|
||||||
purpose: int32;
|
purpose: int32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let size = 4 + 4
|
||||||
|
|
||||||
let bin =
|
let bin =
|
||||||
let open Bin in
|
let open Bin in
|
||||||
record (fun size purpose -> { size; purpose })
|
record (fun size purpose -> { size; purpose })
|
||||||
|+ 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 make size purpose = { size= Int32.of_int size; purpose }
|
||||||
end
|
end
|
||||||
|
|
||||||
(* This is the running SHA512-hash over all
|
(* This is the running SHA512-hash over all
|
||||||
|
|
@ -405,7 +423,7 @@ module Withdraw_request_ps = struct
|
||||||
type t = {
|
type t = {
|
||||||
(* TODO set it in encode/decode *)
|
(* TODO set it in encode/decode *)
|
||||||
(* Purpose is #TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW *)
|
(* Purpose is #TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW *)
|
||||||
purpose: Ecc_signature_purpose.t;
|
purpose: Purpose.t;
|
||||||
(* Amount to withdraw, excluding fees, i.e.
|
(* Amount to withdraw, excluding fees, i.e.
|
||||||
the total sum of the denominations of the coins.
|
the total sum of the denominations of the coins.
|
||||||
Note that the reserve must have a value of at least amount+fee. *)
|
Note that the reserve must have a value of at least amount+fee. *)
|
||||||
|
|
@ -459,7 +477,7 @@ module Withdraw_request_ps = struct
|
||||||
max_age_group;
|
max_age_group;
|
||||||
mask;
|
mask;
|
||||||
})
|
})
|
||||||
|+ field Ecc_signature_purpose.bin (fun t -> t.purpose)
|
|+ field Purpose.bin (fun t -> t.purpose)
|
||||||
|+ field Amount.bin (fun t -> t.amount)
|
|+ field Amount.bin (fun t -> t.amount)
|
||||||
|+ field Amount.bin (fun t -> t.fee)
|
|+ field Amount.bin (fun t -> t.fee)
|
||||||
|+ field Hash_planchets_p.bin (fun t -> t.h_planchets)
|
|+ field Hash_planchets_p.bin (fun t -> t.h_planchets)
|
||||||
|
|
@ -470,10 +488,9 @@ module Withdraw_request_ps = struct
|
||||||
end
|
end
|
||||||
|
|
||||||
module Withdraw_confirmation_ps = struct
|
module Withdraw_confirmation_ps = struct
|
||||||
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;
|
type 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 +506,14 @@ module Withdraw_confirmation_ps = struct
|
||||||
noreveal_index: int32;
|
noreveal_index: int32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let size = Purpose.size + Hash_planchets_p.size + 4
|
||||||
|
let purpose = Purpose.make size 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 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