better if-not-match

This commit is contained in:
swrup 2026-02-12 11:25:57 +01:00
parent 98ba917cfb
commit 85b6dd38ae
167 changed files with 18509 additions and 109 deletions

View file

@ -1 +0,0 @@
A17JXR3E6J4CXDPYT7S1H25PGJ3ABS26TQ38654QCX0TB59RPMF0

View file

@ -1,32 +0,0 @@
let round_trip s =
let s' = s |> B32.encode |> B32.decode |> Result.get_ok in
match s' = s with
| false -> Fmt.failwith "b32 round trip failure: @\nin :`%S`@\nout:`%S`" s' s
| true -> ()
let () =
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; ()
(* TODO *)
(* test vectors from:
https://git.gnunet.org/gnunet/gnunet/file/src/cli/util/crypto-test-vectors.json.html *)
let () =
let input = "91JPRV3F5GG4EKJNDSJQ8" in
let expected =
"D0R24RZ1TPASVQ2NY56CT8AJDYZE9ZGDB0GVZ05E9D4YGZQW2RC5YFPQ0Q86EPW836DY7VYQTNFFJT3ZR2K508F4JVS5JNJKYN2MMFR"
in
let output =
input
|> B32.decode
|> Result.get_ok
|> Hash.H64.hash
|> Hash.H64.to_octets
|> B32.encode
in
assert (output = expected);
()

View file

@ -1,16 +0,0 @@
(test
(name test)
(modules test)
(libraries mte fmt))
(test
(name crypto)
(modules crypto)
(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

View file

@ -1,58 +0,0 @@
#!/bin/bash
set -e
a="/tmp/a.json"
b="/tmp/b.json"
url="http://localhost:3434"
auditor_pub=$(<"./test/auditor_public_key")
master_key="./default/master_offline_private_key"
zero_euro="EUR:0.0"
offline_tool() {
dune exec offline -- "$@" > /dev/null
}
offline_tool download --output $a --url $url"/management/keys"
offline_tool sign \
--master_key $master_key \
--input $a \
--output $b
offline_tool upload --input $b --url $url"/management/keys"
echo "[OK] /management/keys"
offline_tool enable-auditor \
--master_key $master_key \
--output $b \
--auditor_url "auditor.example.com" \
--auditor_name "auditor example" \
--auditor_pub $auditor_pub \
--validity_start 0
offline_tool upload --input $b --url $url"/management/auditors"
echo "[OK] /management/auditors"
offline_tool wire-fee \
--master_key $master_key \
--output $b \
--wire_method "xxx" \
--fee_start 0 \
--fee_end 99999999 \
--closing_fee $zero_euro \
--wire_fee $zero_euro
offline_tool upload --input $b --url $url"/management/wire-fee"
echo "[OK] /management/wire-fee"
offline_tool global-fees \
--master_key $master_key \
--output $b \
--start_date 0 \
--end_date 99999999 \
--history_fee $zero_euro \
--account_fee $zero_euro \
--purse_fee $zero_euro \
--history_expiration 9999999 \
--purse_account_limit 1 \
--purse_timeout 9999999
offline_tool upload --input $b --url $url"/management/global-fees"
echo "[OK] /management/global-fees"

View file

@ -1,55 +0,0 @@
#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;
}

View file

@ -1,108 +0,0 @@
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.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;
*)
()
*)