init
This commit is contained in:
commit
099cd80670
48 changed files with 4951 additions and 0 deletions
11
test/dune
Normal file
11
test/dune
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(test
|
||||
(name test)
|
||||
(modules test)
|
||||
(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;
|
||||
}
|
||||
111
test/test.ml
Normal file
111
test/test.ml
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
let () = Mirage_crypto_rng_unix.use_default ()
|
||||
|
||||
let () =
|
||||
let priv = Mirage_crypto_pk.Rsa.generate ~bits:2048 () in
|
||||
let pub = Mirage_crypto_pk.Rsa.pub_of_priv priv in
|
||||
let () =
|
||||
let open Crypto.RsaPrivateKey in
|
||||
let priv' = priv |> to_octets |> of_octets in
|
||||
assert (to_octets priv = to_octets priv')
|
||||
in
|
||||
let () =
|
||||
let open Crypto.RsaPublicKey in
|
||||
let pub' = pub |> to_octets |> of_octets in
|
||||
assert (to_octets pub = to_octets pub')
|
||||
in
|
||||
()
|
||||
|
||||
let get_ok = function Error e -> failwith e | Ok v -> v
|
||||
|
||||
let () =
|
||||
let open Api in
|
||||
let check jsont s =
|
||||
let encode v = encode jsont v |> get_ok in
|
||||
let decode v = decode jsont v |> get_ok in
|
||||
let ts = decode s in
|
||||
let s' = encode ts in
|
||||
let ts' = decode s' in
|
||||
let s'' = encode ts' in
|
||||
assert (String.equal s' s'')
|
||||
in
|
||||
let check_bad jsont s =
|
||||
let decode = decode jsont in
|
||||
assert (Result.is_error (decode s))
|
||||
in
|
||||
check Timestamp.jsont {|{"t_s": 123456780}|};
|
||||
check Timestamp.jsont {|{"t_s": "never"}|};
|
||||
check_bad Timestamp.jsont {|{"t_s": "123456780"}|};
|
||||
check_bad Timestamp.jsont {|{"t_s": "agagou"}|};
|
||||
|
||||
(* CS not implemented *)
|
||||
check_bad DenominationKey.jsont
|
||||
{|{"cipher": "CS", "age_mask": 18, "cs_pub": "ouhagag"}|};
|
||||
|
||||
(* TODO test with a valid rsa_pub value *)
|
||||
(* TODO handle "rsa pub_of_octets failure" correctly *)
|
||||
(* check_bad DenominationKey.jsont
|
||||
{|{"cipher": "RSA", "age_mask": 18, "rsa_pub": "agagouh"}|}; *)
|
||||
()
|
||||
|
||||
let () =
|
||||
let open Amount in
|
||||
let v =
|
||||
make ~sign:(Some Sign_plus) ~currency:"EUR" ~value:(Int64.of_int 25)
|
||||
~fraction:(Int32.of_int 678)
|
||||
|> Result.get_ok
|
||||
in
|
||||
let s = to_string v in
|
||||
let v' = of_string s |> Result.get_ok in
|
||||
assert (v = v');
|
||||
let r = of_string {|~EUR:4.9|} in
|
||||
assert (Result.is_error r);
|
||||
let r = of_string {|+EUR:4.99999999999999999999999|} in
|
||||
assert (Result.is_error r);
|
||||
()
|
||||
|
||||
let () =
|
||||
let open Headers_lib.Etag in
|
||||
let check input = assert (Result.is_ok (parse input)) in
|
||||
let check_bad input = assert (Result.is_error (parse input)) in
|
||||
|
||||
check "*";
|
||||
check "\"foo\"";
|
||||
check "W/\"foo\"";
|
||||
check "\"foo\", \"bar\"";
|
||||
check " W/\"x\" , W/\"y\" , \"z\" ";
|
||||
check " \"one\" , \"two\" , \"three\" ";
|
||||
check "W/\"a\"";
|
||||
check " W/\"a\" , \"b\"";
|
||||
|
||||
check_bad "";
|
||||
check_bad "foo";
|
||||
check_bad "W/foo";
|
||||
check_bad "W/\"unterminated";
|
||||
check_bad "\"foo\", W/";
|
||||
check_bad "* , \"bar\"";
|
||||
check_bad "\"a\" \"b\"";
|
||||
check_bad "W/\"a\" W/\"b\"";
|
||||
check_bad "\"fo\x7Fo\"";
|
||||
|
||||
(* TODO trailing comma are valid actually, I think *)
|
||||
check_bad "\"foo\" ,";
|
||||
check_bad ", \"foo\"";
|
||||
()
|
||||
|
||||
(*
|
||||
|
||||
let () =
|
||||
let open Binary_formats.WithdrawConfirmationPS in
|
||||
let str64 = String.init 64 (fun i -> Char.unsafe_chr (i + 1)) in
|
||||
let dummy_t = { h_planchets= { hash= str64 }; noreveal_index= 0_l } in
|
||||
let size = Bin.size_of_value bin dummy_t |> Option.get in
|
||||
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