do pg revoke in keys.ml
This commit is contained in:
parent
84472e93dd
commit
efe82de786
160 changed files with 12 additions and 18390 deletions
110
test/test.ml
Normal file
110
test/test.ml
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
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 |> Result.get_ok in
|
||||
assert (to_octets priv = to_octets priv')
|
||||
in
|
||||
let () =
|
||||
let open Crypto.RsaPublicKey in
|
||||
let pub' = pub |> to_octets |> of_octets |> Result.get_ok in
|
||||
assert (to_octets pub = to_octets pub')
|
||||
in
|
||||
()
|
||||
|
||||
let () =
|
||||
let open Api in
|
||||
let check jsont s =
|
||||
let encode v = encode jsont v |> Result.get_ok in
|
||||
let decode v = decode jsont v |> Result.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.If_none_match in
|
||||
let ok_l =
|
||||
[
|
||||
"*";
|
||||
"\"foo\"";
|
||||
"W/\"foo\"";
|
||||
"\"foo\", \"bar\"";
|
||||
" , W/\"x\" , W/\"y\" , \"z\"";
|
||||
", \"one\" , \"two\" , \"three\"";
|
||||
"W/\"a\" , ";
|
||||
"W/\"a\" , \"b\"";
|
||||
]
|
||||
in
|
||||
let bad_l =
|
||||
[
|
||||
"";
|
||||
"foo";
|
||||
"W/foo";
|
||||
"W/\"unterminated";
|
||||
"\"foo\", W/";
|
||||
"* , \"bar\"";
|
||||
"\"a\" \"b\"";
|
||||
"W/\"a\" W/\"b\"";
|
||||
"\"fo\x7Fo\"";
|
||||
" W/\"a\"";
|
||||
"W/\"a\" ";
|
||||
]
|
||||
in
|
||||
let check_ok input = assert (Result.is_ok (parse input)) in
|
||||
let check_bad input = assert (Result.is_error (parse input)) in
|
||||
List.iter check_ok ok_l;
|
||||
List.iter check_bad bad_l;
|
||||
|
||||
()
|
||||
|
||||
let () =
|
||||
let round_trip s =
|
||||
let s' = s |> B32.encode |> B32.decode |> Result.get_ok in
|
||||
assert (s = s')
|
||||
in
|
||||
let s = String.init 0xff Char.chr in
|
||||
round_trip s;
|
||||
let s_l = List.init 0x0f (fun i -> String.init i Char.chr) in
|
||||
List.iter round_trip s_l;
|
||||
|
||||
()
|
||||
Loading…
Add table
Add a link
Reference in a new issue