JJ: Description from the destination commit:
more module renaming JJ: Description from source commit: test binary_formats
This commit is contained in:
parent
e4b9fb473a
commit
1112106eb2
7 changed files with 114 additions and 39 deletions
|
|
@ -364,7 +364,7 @@ module BlindingMasterSeed = MK_BASIC_32 ()
|
||||||
|
|
||||||
(* Format used for to generate the signature on a request to withdraw
|
(* Format used for to generate the signature on a request to withdraw
|
||||||
coins from a reserve. *)
|
coins from a reserve. *)
|
||||||
module WithdrawRequestPs = struct
|
module WithdrawRequestPS = struct
|
||||||
(* Purpose is #TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW *)
|
(* Purpose is #TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW *)
|
||||||
type t = {
|
type t = {
|
||||||
(* Amount to withdraw, excluding fees, i.e.
|
(* Amount to withdraw, excluding fees, i.e.
|
||||||
|
|
@ -432,7 +432,7 @@ module WithdrawRequestPs = struct
|
||||||
|> sealr
|
|> sealr
|
||||||
end
|
end
|
||||||
|
|
||||||
module WithdrawConfirmationPs = struct
|
module WithdrawConfirmationPS = struct
|
||||||
(* 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. *)
|
||||||
type t = {
|
type t = {
|
||||||
|
|
@ -451,15 +451,23 @@ module WithdrawConfirmationPs = struct
|
||||||
noreveal_index: int32;
|
noreveal_index: int32;
|
||||||
}
|
}
|
||||||
|
|
||||||
let size = Purpose.size + HashPlanchetsP.size + int32_size
|
(*let size = Purpose.size + HashPlanchetsP.size + int32_size*)
|
||||||
let purpose = Purpose.make ~size Taler_signatures.exchange_confirm_withdraw
|
|
||||||
|
open Bin
|
||||||
|
|
||||||
let bin =
|
let bin =
|
||||||
let open Bin in
|
record (fun purpose h_planchets noreveal_index ->
|
||||||
record (fun _urpose h_planchets noreveal_index ->
|
(purpose, { h_planchets; noreveal_index }))
|
||||||
{ h_planchets; noreveal_index })
|
|+ field Purpose.bin (fun (purpose, _t) -> purpose)
|
||||||
|+ field Purpose.bin (Fun.const purpose)
|
|+ field HashPlanchetsP.bin (fun (_p, t) -> t.h_planchets)
|
||||||
|+ field HashPlanchetsP.bin (fun t -> t.h_planchets)
|
|+ field beint32 (fun (_p, t) -> t.noreveal_index)
|
||||||
|+ field beint32 (fun t -> t.noreveal_index)
|
|
||||||
|> sealr
|
|> sealr
|
||||||
|
|
||||||
|
let size =
|
||||||
|
match Size.of_value (Size.size_of bin) with
|
||||||
|
| Dynamic _ | Unknown -> Fmt.failwith "size_of failure: size is not Static"
|
||||||
|
| Static n -> n
|
||||||
|
|
||||||
|
let purpose = Purpose.make ~size Taler_signatures.exchange_confirm_withdraw
|
||||||
|
let bin = map bin (fun (_p, t) -> t) (fun t -> (purpose, t))
|
||||||
end
|
end
|
||||||
|
|
|
||||||
28
src/json.ml
28
src/json.ml
|
|
@ -4,8 +4,8 @@ let encode_exn jsont v = Jsont_bytesrw.encode_string jsont v |> Result.get_ok
|
||||||
let encode jsont v = Jsont_bytesrw.encode_string jsont v
|
let encode jsont v = Jsont_bytesrw.encode_string jsont v
|
||||||
let decode jsont v = Jsont_bytesrw.decode_string jsont v
|
let decode jsont v = Jsont_bytesrw.decode_string jsont v
|
||||||
|
|
||||||
module Error_detail = struct
|
module ErrorDetail = struct
|
||||||
open Error_detail
|
open ErrorDetail
|
||||||
|
|
||||||
let jsont =
|
let jsont =
|
||||||
let make code hint = { code; hint } in
|
let make code hint = { code; hint } in
|
||||||
|
|
@ -45,8 +45,8 @@ module Timestamp = struct
|
||||||
|> Jsont.Object.finish
|
|> Jsont.Object.finish
|
||||||
end
|
end
|
||||||
|
|
||||||
module Relative_time = struct
|
module RelativeTime = struct
|
||||||
open Relative_time
|
open RelativeTime
|
||||||
|
|
||||||
let number_or_forever_jsont =
|
let number_or_forever_jsont =
|
||||||
let forever =
|
let forever =
|
||||||
|
|
@ -87,8 +87,8 @@ module Eddsa = struct
|
||||||
let signature_jsont = Jsont.string
|
let signature_jsont = Jsont.string
|
||||||
end
|
end
|
||||||
|
|
||||||
module Rsa_denomination_key = struct
|
module RsaDenominationKey = struct
|
||||||
open Rsa_denomination_key
|
open RsaDenominationKey
|
||||||
|
|
||||||
let jsont =
|
let jsont =
|
||||||
let make age_mask rsa_pub = { age_mask; rsa_pub } in
|
let make age_mask rsa_pub = { age_mask; rsa_pub } in
|
||||||
|
|
@ -100,8 +100,8 @@ module Rsa_denomination_key = struct
|
||||||
|> Jsont.Object.finish
|
|> Jsont.Object.finish
|
||||||
end
|
end
|
||||||
|
|
||||||
module CS_denomination_key = struct
|
module CSDenominationKey = struct
|
||||||
open CS_denomination_key
|
open CSDenominationKey
|
||||||
|
|
||||||
let jsont =
|
let jsont =
|
||||||
let make age_mask cs_pub = { age_mask; cs_pub } in
|
let make age_mask cs_pub = { age_mask; cs_pub } in
|
||||||
|
|
@ -113,16 +113,16 @@ module CS_denomination_key = struct
|
||||||
|> Jsont.Object.finish
|
|> Jsont.Object.finish
|
||||||
end
|
end
|
||||||
|
|
||||||
module Denomination_key = struct
|
module DenominationKey = struct
|
||||||
open Denomination_key
|
open DenominationKey
|
||||||
|
|
||||||
let rsa v = Rsa v
|
let rsa v = Rsa v
|
||||||
let cs v = CS v
|
let cs v = CS v
|
||||||
|
|
||||||
let jsont =
|
let jsont =
|
||||||
let open Jsont.Object in
|
let open Jsont.Object in
|
||||||
let rsa = Case.map "RSA" Rsa_denomination_key.jsont ~dec:rsa in
|
let rsa = Case.map "RSA" RsaDenominationKey.jsont ~dec:rsa in
|
||||||
let cs = Case.map "CS" CS_denomination_key.jsont ~dec:cs in
|
let cs = Case.map "CS" CSDenominationKey.jsont ~dec:cs in
|
||||||
let enc_case = function
|
let enc_case = function
|
||||||
| Rsa v -> Case.value rsa v
|
| Rsa v -> Case.value rsa v
|
||||||
| CS v -> Case.value cs v
|
| CS v -> Case.value cs v
|
||||||
|
|
@ -133,8 +133,8 @@ module Denomination_key = struct
|
||||||
|> finish
|
|> finish
|
||||||
end
|
end
|
||||||
|
|
||||||
module Future_sign_key = struct
|
module FutureSignKey = struct
|
||||||
open Future_sign_key
|
open FutureSignKey
|
||||||
|
|
||||||
let jsont =
|
let jsont =
|
||||||
(* TODO ppx? *)
|
(* TODO ppx? *)
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,10 @@
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. *)
|
along with this program. If not, see <https://www.gnu.org/licenses/>. *)
|
||||||
|
|
||||||
let error_detail ?hint _status =
|
let error_detail ?hint _status =
|
||||||
let open Types.Error_detail in
|
let open Types.ErrorDetail in
|
||||||
let open Json in
|
let open Json in
|
||||||
let code = -1 in
|
let code = -1 in
|
||||||
let s = encode_exn Error_detail.jsont { code; hint } in
|
let s = encode_exn ErrorDetail.jsont { code; hint } in
|
||||||
s
|
s
|
||||||
|
|
||||||
module Respond_with = struct
|
module Respond_with = struct
|
||||||
|
|
|
||||||
18
src/types.ml
18
src/types.ml
|
|
@ -1,5 +1,5 @@
|
||||||
(* https://docs.taler.net/core/api-common.html#tsref-type-ErrorDetail *)
|
(* https://docs.taler.net/core/api-common.html#tsref-type-ErrorDetail *)
|
||||||
module Error_detail = struct
|
module ErrorDetail = struct
|
||||||
(* TODO GANA error codes
|
(* TODO GANA error codes
|
||||||
https://git.gnunet.org/gana.git/tree/gnu-taler-error-codes/registry.rec *)
|
https://git.gnunet.org/gana.git/tree/gnu-taler-error-codes/registry.rec *)
|
||||||
type t = {
|
type t = {
|
||||||
|
|
@ -21,7 +21,7 @@ module Timestamp = struct
|
||||||
| Never
|
| Never
|
||||||
end
|
end
|
||||||
|
|
||||||
module Relative_time = struct
|
module RelativeTime = struct
|
||||||
(* Duration in microseconds or "forever"
|
(* Duration in microseconds or "forever"
|
||||||
to represent an infinite duration. Numeric
|
to represent an infinite duration. Numeric
|
||||||
values are capped at 2^53 - 1 inclusive. *)
|
values are capped at 2^53 - 1 inclusive. *)
|
||||||
|
|
@ -147,19 +147,19 @@ module Rsa = struct
|
||||||
let pub_to_string _pub = assert false
|
let pub_to_string _pub = assert false
|
||||||
end
|
end
|
||||||
|
|
||||||
module Hash_code = struct
|
module HashCode = struct
|
||||||
(* 32-byte value representing a point on Curve25519. *)
|
(* 32-byte value representing a point on Curve25519. *)
|
||||||
type cs25519Point = string
|
type cs25519Point = string
|
||||||
end
|
end
|
||||||
|
|
||||||
module Rsa_denomination_key = struct
|
module RsaDenominationKey = struct
|
||||||
type t = {
|
type t = {
|
||||||
age_mask: int;
|
age_mask: int;
|
||||||
rsa_pub: string; (* Rsa.pub *)
|
rsa_pub: string; (* Rsa.pub *)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
module CS_denomination_key = struct
|
module CSDenominationKey = struct
|
||||||
(* Clause Schnorr *)
|
(* Clause Schnorr *)
|
||||||
type t = {
|
type t = {
|
||||||
age_mask: int;
|
age_mask: int;
|
||||||
|
|
@ -167,13 +167,13 @@ module CS_denomination_key = struct
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
module Denomination_key = struct
|
module DenominationKey = struct
|
||||||
type t =
|
type t =
|
||||||
| Rsa of Rsa_denomination_key.t
|
| Rsa of RsaDenominationKey.t
|
||||||
| CS of CS_denomination_key.t
|
| CS of CSDenominationKey.t
|
||||||
end
|
end
|
||||||
|
|
||||||
module Future_sign_key = struct
|
module FutureSignKey = struct
|
||||||
type t = {
|
type t = {
|
||||||
(* The actual exchange's EdDSA signing public key *)
|
(* The actual exchange's EdDSA signing public key *)
|
||||||
key: Eddsa.pub;
|
key: Eddsa.pub;
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,10 @@
|
||||||
(name test)
|
(name test)
|
||||||
(modules test)
|
(modules test)
|
||||||
(libraries mte fmt))
|
(libraries mte fmt))
|
||||||
|
|
||||||
|
; TODO
|
||||||
|
; cram test?
|
||||||
|
; gcc -o a.out ./test/signatures.c && ./a.out > a.output
|
||||||
|
; rm ./a.out
|
||||||
|
; dune exec ./test/test.exe > b.output
|
||||||
|
; cmp -l a.output b.output
|
||||||
|
|
|
||||||
55
test/signatures.c
Normal file
55
test/signatures.c
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct H64 {
|
||||||
|
uint8_t hash[64];
|
||||||
|
};
|
||||||
|
struct Hhh {
|
||||||
|
struct H64 hash;
|
||||||
|
};
|
||||||
|
struct Purpose {
|
||||||
|
uint32_t size;
|
||||||
|
uint32_t purpose;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PS {
|
||||||
|
struct Purpose purpose;
|
||||||
|
struct Hhh h;
|
||||||
|
uint32_t noreveal_index;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct Purpose purpose;
|
||||||
|
struct PS ps;
|
||||||
|
|
||||||
|
purpose.size = 3 * 4 + 64;
|
||||||
|
purpose.purpose = 1050;
|
||||||
|
|
||||||
|
struct Hhh h = {
|
||||||
|
.hash = {
|
||||||
|
.hash = {
|
||||||
|
1 , 2 , 3 , 4 , 5, 6, 7, 8,
|
||||||
|
9 , 10, 11, 12, 13, 14, 15, 16,
|
||||||
|
17, 18, 19, 20, 21, 22, 23, 24,
|
||||||
|
25, 26, 27, 28, 29, 30, 31, 32,
|
||||||
|
33, 34, 35, 36, 37, 38, 39, 40,
|
||||||
|
41, 42, 43, 44, 45, 46, 47, 48,
|
||||||
|
49, 50, 51, 52, 53, 54, 55, 56,
|
||||||
|
57, 58, 59, 60, 61, 62, 63, 64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t noreveal_index = 0;
|
||||||
|
|
||||||
|
ps.purpose = purpose;
|
||||||
|
ps.h = h;
|
||||||
|
ps.noreveal_index = noreveal_index;
|
||||||
|
|
||||||
|
|
||||||
|
fwrite(&ps, sizeof(ps), 1, stdout);
|
||||||
|
|
||||||
|
// printf("\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
13
test/test.ml
13
test/test.ml
|
|
@ -18,9 +18,9 @@ let () =
|
||||||
check_bad Timestamp.jsont {|{"t_s": "123456780"}|};
|
check_bad Timestamp.jsont {|{"t_s": "123456780"}|};
|
||||||
check_bad Timestamp.jsont {|{"t_s": "agagou"}|};
|
check_bad Timestamp.jsont {|{"t_s": "agagou"}|};
|
||||||
|
|
||||||
check Denomination_key.jsont
|
check DenominationKey.jsont
|
||||||
{|{"cipher": "RSA", "age_mask": 18, "rsa_pub": "agagouh"}|};
|
{|{"cipher": "RSA", "age_mask": 18, "rsa_pub": "agagouh"}|};
|
||||||
check Denomination_key.jsont
|
check DenominationKey.jsont
|
||||||
{|{"cipher": "CS", "age_mask": 18, "cs_pub": "ouhagag"}|};
|
{|{"cipher": "CS", "age_mask": 18, "cs_pub": "ouhagag"}|};
|
||||||
()
|
()
|
||||||
|
|
||||||
|
|
@ -73,10 +73,15 @@ let () =
|
||||||
()
|
()
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
let open Binary_formats.WithdrawConfirmationPs in
|
let open Binary_formats.WithdrawConfirmationPS in
|
||||||
let str64 = String.make 64 '0' in
|
let str64 = String.init 64 (fun i -> Char.unsafe_chr (i + 1)) in
|
||||||
let dummy_t = { h_planchets= { v= { v= str64 } }; noreveal_index= 0_l } in
|
let dummy_t = { h_planchets= { v= { v= str64 } }; noreveal_index= 0_l } in
|
||||||
let size' = Bin.size_of_value bin dummy_t |> Option.get in
|
let size' = Bin.size_of_value bin dummy_t |> Option.get in
|
||||||
assert (size = size');
|
assert (size = size');
|
||||||
assert (size = 76);
|
assert (size = 76);
|
||||||
|
|
||||||
|
(* for cmp test with signatures.c output *)
|
||||||
|
let raw_str = Bin.to_string bin dummy_t in
|
||||||
|
Printf.printf "%s" raw_str;
|
||||||
|
|
||||||
()
|
()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue