text stringlengths 12 786k |
|---|
let rsa_pkcs1_encode_selftest ~ bits n = " selftest " >:: times ~ n @@ fun _ -> let ( key , _ ) = gen_rsa ~ bits and msg = pkcs_message_for_bits bits in let sgn = Rsa . PKCS1 . sig_encode ~ key msg in match Rsa . ( PKCS1 . sig_decode ~ key ( : pub_of_priv key ) sgn ) with | Non... |
let rsa_pkcs1_sign_selftest n = let open Hash . SHA1 in " selftest " >:: times ~ n @@ fun _ -> let ( key , _ ) = gen_rsa ~ bits ( : Rsa . PKCS1 . min_key ` SHA1 ) and msg = Mirage_crypto_rng . generate 47 in let pkey = Rsa . pub_of_priv key in assert_bool " invert 1 " Rsa . ... |
let rsa_pkcs1_encrypt_selftest ~ bits n = " selftest " >:: times ~ n @@ fun _ -> let ( key , _ ) = gen_rsa ~ bits and msg = pkcs_message_for_bits bits in let enc = Rsa . ( PKCS1 . encrypt ~ key ( : pub_of_priv key ) msg ) in match Rsa . PKCS1 . decrypt ~ key enc with | None ->... |
let rsa_oaep_encrypt_selftest ~ bits n = let hashes = [ | ` MD5 ; ` SHA1 ; ` SHA224 ; ` SHA256 ] | in " selftest " >:: times ~ n @@ fun _ -> let module H = ( val ( Hash . module_of ( sample hashes ) ) ) in let module OAEP = Rsa . OAEP ( H ) in let ( key , _ ) ... |
let rsa_pss_sign_selftest ~ bits n = let module Pss_sha1 = Rsa . PSS ( Hash . SHA1 ) in let open Hash . SHA1 in " selftest " >:: times ~ n @@ fun _ -> let ( key , _ ) = gen_rsa ~ bits and msg = Mirage_crypto_rng . generate 1024 in let pkey = Rsa . pub_of_priv key in Pss_sha1 . ( ... |
let rsa_pkcs1_cases = let key ( ) = let n = vz " c8a2069182394a2ab7c3f4190c15589c56a2d4bc42dca675b34cc950e24663048441e8aa593b2bc59e198b8c257e882120c62336e5cc745012c7ffb063eebe53f3c6504cba6cfe51baa3b6d1074b2f398171f4b1982f4d65caf882ea4d56f32ab57d0c44e6ad4e9cf57a4339eb6962406e350c1b15397183fbf1f0353c9fc991 " a... |
let rsa_pss_cases = let key ( ) = let n = vz " bcb47b2e0dafcba81ff2a2b5cb115ca7e757184c9d72bcdcda707a146b3b4e29989ddc660bd694865b932b71ca24a335cf4d339c719183e6222e4c9ea6875acd528a49ba21863fe08147c3a47e41990b51a03f77d22137f8d74c43a5a45f4e9e18a2d15db051dc89385db9cf8374b63a8cc88113710e6d8179075b7dc79ee76b " and... |
let suite = [ " RSA " >::: [ rsa_selftest ~ bits : 89 100 ; rsa_selftest ~ bits : 131 100 ; rsa_selftest ~ bits : 1024 10 ; rsa_selftest ~ bits : 2048 10 ; ] ; " RSA - PKCS1 - ENC " >::: [ rsa_pkcs1_encrypt_selftest ~ bits : 111 1000 ; rsa_pkcs1_encrypt_selftest ~ b... |
let rules ( t : Dune_file . Tests . t ) ~ sctx ~ dir ~ scope ~ expander ~ dir_contents = let test_kind ( loc , name ) = let files = Dir_contents . text_files dir_contents in let expected_basename = name ^ " . expected " in if String . Set . mem files expected_basename then ` Expec... |
let is_opt x = String . length x > 1 && x [ . 0 ] 0 = ' - ' |
let parse_opt_arg x = let l = String . length x in if x [ . 1 ] 1 <> ' - ' then if l = 2 then ( x , None ) None else ( String . sub x 0 2 , Some ( String . sub x 2 ( l - 2 ) 2 ) 2 ) 2 else try let i = String . index x ' = ' in ( String . sub x 0 i , Some ... |
type arg = | Path of Fpath . t | Library of [ ` Abs of Fpath . t | ` Rel of Fpath . t | ` Name of string ] |
let parse_lL_value name value = match name with | " - L " -> ( match Fpath . of_string value with | Ok v when Fpath . is_dir_path v && Sys . is_directory value -> R . ok ( Path v ) v | Ok v when Sys . is_directory value -> R . ok ( Path ( Fpath . to_dir_path v ) v ) v | Ok v -> R . er... |
let parse_lL_args args = let rec go lL_args = function | [ ] | " " -- :: _ -> R . ok ( List . rev lL_args ) lL_args | x :: args -> ( if not ( is_opt x ) x then go lL_args args else let name , value = parse_opt_arg x in match name with | " - L " | " - l " -> ( match value with ... |
let is_path = function Path _ -> true | Library _ -> false |
let prj_path = function Path x -> x | _ -> assert false |
let prj_libraries = function Library x -> x | _ -> assert false |
let libraries_exist args = let paths , libraries = List . partition is_path args in let paths = List . map prj_path paths in let libraries = List . map prj_libraries libraries in let rec go = function | [ ] -> R . ok ( ) | ` Rel library :: libraries -> let rec check = function | [ ] -> ... |
let exists lib = let open Bos in let command = Cmd ( . v " ocamlfind " % " query " % lib ) lib in OS . Cmd . run_out command |> OS . Cmd . out_null >>= function | ( ) , ( _ , ` Exited 0 ) 0 -> R . ok true | _ -> R . ok false |
let query target lib = let open Bos in let format = Fmt . str " - L %% d ( %%% s_linkopts ) s_linkopts " target in let command = Cmd ( . v " ocamlfind " % " query " % " - format " % format % lib ) lib in OS . Cmd . run_out command |> OS . Cmd . out_lines >>= ( function | output ... |
let run ( ) = ( exists " mirage - xen - posix " >>= function | true -> query " xen " " digestif " >>= parse_lL_args >>= libraries_exist | false -> R . ok ( ) ) >>= fun ( ) -> ( exists " ocaml - freestanding " >>= function | true -> query " freestanding " " digest... |
let ( ) = match run ( ) with | Ok ( ) -> exit exit_success | Error ( ` Msg err ) err -> Fmt . epr " % s \ n " %! err ; exit exit_failure |
let rec count acc = function | TestCase _ -> acc + 1 | TestLabel ( _ , test ) -> count acc test | TestList l -> List . fold_left l ~ f : count ~ init : acc |
let count_pa_ounit = function | TestList l -> List . fold_left l ~ f ( : fun ( pa_ounit , total ) test -> match test with | TestLabel ( s , tst ) when String . is_suffix ~ suffix " . : ml " s -> let cnt = count 0 tst in ( pa_ounit + cnt , total + cnt ) | test -> pa_ounit , ... |
let main ( ) = let cnt_ounit = " - cnt " , Arg . Unit ( fun ( ) -> let pa_ounit , total = count_pa_ounit ( Test . all ( ) ) in Printf . printf " converted : % i total : % i \ n " %! pa_ounit total ; exit 0 ) , " Count how many of the tests were converted to pa_oun... |
let ( ) = Exn . handle_uncaught ~ exit : true main |
let test_sexping = let tests = [ " 1 " , " https :// example . com / foo ? bar = 1 # frag " , " ( ( scheme ( https ) ) ( host ( example . com ) ) ( path / foo ) ( query ( ( bar ( 1 ) ) ) ) ( fragment ( frag ) ) ) " ; " 2 " , " "... |
let rec was_successful = function | [ ] -> true | RSuccess _ :: t | RSkip _ :: t -> was_successful t | RFailure _ :: _ | RError _ :: _ | RTodo _ :: _ -> false |
let _ = let suite = " URI - SEXP " >::: ( test_sexping ) in let verbose = ref false in let set_verbose _ = verbose := true in Arg . parse [ ( " - verbose " , Arg . Unit set_verbose , " Run the test in verbose mode . " ) ; ] ( fun x -> raise ( Arg . Bad ( " Bad ar... |
module Util = struct [ %% declare_roles_prefixed a , b , c , d ] [ %% declare_labels msg , left , right , middle , ping , pong , fini ] end |
let test_run_infinite_loop ( ) = assert_equal ( ) @@ let _g0 = extract @@ choice_at a [ % disj role_B ( left , right ) ] ( a , loop_with [ a ; b ] ( fun t -> ( a --> b ) left t ) ) ( a , loop_with [ a ; b ] ( fun t -> ( a --> b ) right t ) ) in let ( ... |
let test_run_infinite_loop2 ( ) = assert_equal ( ) @@ let _g0 = extract @@ loop_with [ a ; b ] ( fun t -> ( a ==> b ) @@ ( a ==> b ) t ) in let ( ` cons ( sa , ` cons ( sb , # nil ) ) ) = _g0 in let ta = Thread . create ( fun ( ) -> let rec f sa i = i... |
let test_run_infinite_input_merge ( ) = assert_equal ( ) @@ let g = extract @@ choice_at a [ % disj role_B ( left , right ) ] ( a , loop_with [ a ; b ; c ] ( fun t -> ( a --> b ) left @@ ( a --> c ) msg t ) ) ( a , loop_with [ a ; b ; c ] ( fun t -> ( ... |
let test_run_unbalanced_choice ( ) = assert_equal ( ) @@ let g = extract @@ loop_with [ a ; b ; c ] ( fun t -> choice_at a [ % disj role_B ( left , right ) ] ( a , ( a --> b ) left t ) ( a , ( a --> b ) right @@ ( b --> c ) right finish ) ) in let ( ` ... |
let test_run_unbalanced_choice_nested ( ) = assert_equal ( ) @@ let g = extract @@ loop_with [ a ; b ; c ] ( fun t -> choice_at a [ % disj role_B ( [ left ; middle ] , right ) ] ( a , choice_at a [ % disj role_B ( left , middle ) ] ( a , ( a --> b ) left t... |
let test_run_unbalanced_choice_nested2 ( ) = assert_equal ( ) @@ let g = extract @@ loop_with [ a ; b ; c ] ( fun t1 -> choice_at a [ % disj role_B ( left , [ middle ; right ] ) ] ( a , ( a --> b ) left @@ ( a --> c ) left finish ) ( a , loop_with [ a ; b... |
let test_run_unguarded_choice_alternative ( ) = assert_equal ( ) @@ let g = extract @@ loop_with [ a ; b ] ( fun t -> ( a --> b ) left @@ loop_with [ a ; b ] ( fun u -> choice_at a [ % disj role_B ( left , right ) ] ( a , t ) ( a , ( a --> b ) right @@ u ) ... |
let test_run_unguarded_choice_alternative_unbalanced ( ) = let g = extract @@ loop_with [ a ; b ; c ] ( fun t -> ( a --> b ) left @@ choice_at a [ % disj role_B ( left , right ) ] ( a , t ) ( a , ( a --> b ) right @@ ( b --> c ) right @@ finish ) ) in let ( ... |
let test_run_partially_unguarded_choice_alternative ( ) = assert_equal ( ) @@ let g = extract @@ loop_with [ a ; b ; c ] ( fun t -> ( a --> b ) msg @@ choice_at a [ % disj role_C ( left , right ) ] ( a , ( a --> c ) left @@ ( c --> a ) msg t ) ( a , ( a --... |
let test_run_fourparty ( ) = let run i = let g = extract @@ choice_at d [ % disj role_C ( [ left ; middle ] , right ) ] ( d , choice_at d [ % disj role_C ( left , middle ) ] ( d , ( d --> c ) left @@ ( d --> b ) left @@ ( c --> a ) left @@ ( a --> b ) l... |
let suite = " Running mpst communication " >::: [ " test_run_infinite_loop " >:: test_run_infinite_loop ; " test_run_infinite_loops " >:: test_run_infinite_loop2 ; " test_run_infinite_input_merge " >:: test_run_infinite_input_merge ; " test_run_unbalanced_choice " >:: test_run_unbalanc... |
let _results = run_test_tt_main suite in ( ) |
module Util = struct [ %% declare_roles_prefixed a , b , c , d ] [ %% declare_labels msg , left , right , middle , ping , pong , fini ] end |
let test_run_infinite_loop ( ) = assert_equal ( ) @@ let _g0 = extract_with [ P ( b , 5 ) ] @@ choice_at a [ % disj role_B ( left , right ) ] ( a , loop_with [ a ; b ] ( fun t -> ( a -->@@ b ) left t ) ) ( a , loop_with [ a ; b ] ( fun t -> ( a --... |
let suite = " Running multicast communication " >::: [ " test_run_infinite_loop " >:: test_run_infinite_loop ] ; ; |
let _results = run_test_tt_main suite in ( ) |
let test_find_params ( ) = let test ~ env ~ files ( ? cwd = " . " ) expected_result = let fail x = Printf . ksprintf ( fun s -> Alcotest . failf " % s with environment [ % s ] and files [ % s ] " s ( List . map ( fun ( n , v ) -> n ^ " , " ^ v ) env |> ... |
let test_init ( ) = Rustzcash . init_params ( ) |
let test_ctx_prove ( ) = let rec loop n = if n <= 0 then ( ) else let ctx = Rustzcash . proving_ctx_init ( ) in Gc . full_major ( ) ; Rustzcash . proving_ctx_free ctx ; Gc . full_major ( ) ; loop ( n - 1 ) in loop 100 |
let test_ctx_verif ( ) = let rec loop n = if n <= 0 then ( ) else let ctx = Rustzcash . verification_ctx_init ( ) in Gc . full_major ( ) ; Rustzcash . verification_ctx_free ctx ; Gc . full_major ( ) ; loop ( n - 1 ) in loop 100 |
let test_fail_make_binding_sig ( ) = let balance = Int64 . succ Rustzcash . max_amount in let proving_ctx = Rustzcash . proving_ctx_init ( ) in let sighash = Rustzcash . to_sighash @@ Bytes . create 32 in try let _ = Rustzcash . make_binding_sig proving_ctx ~ balance sighash in Rustzcash . ... |
let test_fail_final_check ( ) = let verification_ctx = Rustzcash . verification_ctx_init ( ) in let balance = Int64 . succ Rustzcash . max_amount in let sighash = Rustzcash . to_sighash @@ Bytes . create 32 in let binding_sig = Rustzcash . to_binding_sig @@ Bytes . create 64 in try let _ ... |
let test_ivk_to_pkd ( ) = let test_inputs = [ ( " 308bc4ae65c4cac5b53d1b381b44516e345a1cea6188449d203545c542df0a05 " , " ad56e205a5b571a37d55db " , " b506a8f09503d75d5b2c8695406da89b115e75a29235848544f59d993b7f460b " ) ; ( " 173f3720483b1c083e473d3e224b332827440a33064024383b0a02192532... |
let test_failing_ivk_to_pkd ( ) = let test_inputs = [ ( " 0254fb145abaae0c9e48ab452da04e961201c0332b3eac4e6bd0bf184c8ebca3 " , " b87451711fd507357488d2 " ) ; ( " 3fdc0e75f7481fd37a299491cb38075a7154a5f2bf0453fab010b2331510ceea " , " 2fcb83c49f854535ac2924 " ) ; ] in List . ... |
let tests = [ ( " find params " , ` Quick , test_find_params ) ; ( " init " , ` Quick , test_init ) ; ( " proving context " , ` Quick , test_ctx_prove ) ; ( " verification context " , ` Quick , test_ctx_verif ) ; ( " fail binding_sig " , ` Qui... |
let ( ) = Alcotest . run " sapling " [ ( " rustzcash " , tests ) ] |
module Int = struct include Int let hash = Hashtbl . hash end |
let equal_array elt_eq arr1 arr2 = Array . length arr1 = Array . length arr2 && Stdlib . List . for_all2 elt_eq ( Array . to_list arr1 ) ( Array . to_list arr2 ) |
let support cmp array = Array . to_seq array |> Seq . map fst |> List . of_seq |> List . sort cmp |> Array . of_list |
let support_uniq cmp array = Array . to_seq array |> Seq . map fst |> List . of_seq |> List . sort_uniq cmp |> Array . of_list |
module type Std = sig type t val equal : t -> t -> bool val compare : t -> t -> int val hash : t -> int end |
module Helpers = struct let sample_n_times ( total : int ) sample = let rec loop n acc = if n = 0 then acc else let res = sample ( ) in loop ( n - 1 ) ( res :: acc ) in loop total [ ] let empirical_distribution : type a . ( module Std with type t = a ) -> nsamples : int -> ( u... |
let normalize : ( ' a * int ) array -> ( ' a * Q . t ) array = fun empirical -> let total = Array . fold_left ( fun acc ( _ , weight ) -> Z . add ( Z . of_int weight ) acc ) Z . zero empirical in Array . map ( fun ( n , weight ) -> ( n , Q . ( Z . of_int... |
let pp_dist pp fmtr dist = let l = Array . to_list dist in Format . pp_print_list ~ pp_sep ( : fun fmtr ( ) -> Format . fprintf fmtr " , " ) ( fun fmtr ( elt , w ) -> Format . fprintf fmtr " ( % a , % f ) " pp elt ( Q . to_float w ) ) fmtr l |
let linf ( dist : ( ' a * Q . t ) array ) pmf = Array . fold_left ( fun acc ( n , q ) -> Q . ( max acc ( abs ( pmf n - q ) ) ) ) Q . zero dist |
let state = Random . State . make [ | 0x1337533D ; 71287309 ; 666932349 ; 719132214 ; 461480042 ; 387006837 ; 443018964 ; 450865457 ; 901711679 ; 833353016 ; 397060904 ; ] | |
module Make_test ( Mass : sig include SMass val to_float : t -> float val sample : int_bound : int -> mass_bound : Mass . t -> int * Mass . t struct let make p = let module Probability = Internal_for_tests . Make ( Mass ) in let measure = List . mapi ( fun i p -> ( i , p ) ) p in le... |
module Probability_mass_float : SMass with type t = float = struct type t = float let encoding = Data_encoding . float let zero = 0 . 0 let of_int = float_of_int let mul = ( . * ) let add = ( . + ) let sub = ( . - ) let ( = ) = Float . equal let ( <= ) ( x : t ) ( ... |
module Test_float = Make_test ( struct include Probability_mass_float let to_float x = x end ) ( struct let sample ~ int_bound ~ mass_bound = ( Random . State . int state int_bound , Random . State . float state mass_bound ) end ) |
module Probability_mass_z : SMass with type t = Z . t = struct let encoding = Data_encoding . z include Z include Z . Compare end |
module Test_z = Make_test ( struct include Probability_mass_z let to_float = Z . to_float end ) ( struct let sample ~ int_bound ~ mass_bound = ( Random . State . int state int_bound , Z . of_int64 ( Random . State . int64 state ( Z . to_int64 mass_bound ) ) ) end ) |
let qcheck_wrap = qcheck_wrap ~ rand : state |
let alias_float_test = QCheck . Test . make ~ count : 100 ~ name " : alias_float " QCheck . ( list_of_size ( Gen . int_range 1 20 ) pos_float ) Test_float . make |
let alias_z_test = QCheck . Test . make ~ count : 100 ~ name " : alias_z " QCheck . ( list_of_size ( Gen . int_range 1 20 ) ( make Gen . ( nat >>= fun n -> return ( Z . of_int n ) ) ) ) Test_z . make |
let ( ) = Alcotest . run " Sampling " [ ( " sampling " , qcheck_wrap [ alias_float_test ; alias_z_test ] ) ] |
let verbose = if Array . length Sys . argv < 2 then ( Format . eprintf " Executable expects random seed on input \ n " %! ; exit 1 ) else ( Random . init ( int_of_string Sys . argv . ( 1 ) ) ; List . exists ( ( = ) " - v " ) ) ( Array . to_list Sys . argv... |
let state = Random . State . make [ | 42 ; 987897 ; 54120 ] | |
module Crypto_samplers = Crypto_samplers . Make_finite_key_pool ( struct let algo = ` Default let size = 16 end ) |
module Michelson_base_samplers = Michelson_samplers_base . Make ( struct let parameters = let size = { Base_samplers . min = 4 ; max = 32 } in { Michelson_samplers_base . int_size = size ; string_size = size ; bytes_size = size ; } end ) |
module Code = Michelson_mcmc_samplers . Make_code_sampler ( Michelson_base_samplers ) ( Crypto_samplers ) ( struct let rng_state = state let target_size = 500 let verbosity = if verbose then ` Trace else ` Silent end ) |
let start = Unix . gettimeofday ( ) |
let generator = Code . generator ~ burn_in ( : 500 * 7 ) state |
let stop = Unix . gettimeofday ( ) |
let ( ) = Format . printf " Burn in time : % f seconds . " @ ( stop . - start ) |
let _ = for i = 1 to 1000 do let Michelson_mcmc_samplers . { term = michelson ; bef ; aft } = generator state in Test_helpers . typecheck_by_tezos bef michelson ; if verbose then ( Format . eprintf " result % d / 1000 . " :@ i ; Format . eprintf " type : % a => % a . " ... |
let verbose = if Array . length Sys . argv < 2 then ( Format . eprintf " Executable expects random seed on input \ n " %! ; exit 1 ) else ( Random . init ( int_of_string Sys . argv . ( 1 ) ) ; List . exists ( ( = ) " - v " ) ) ( Array . to_list Sys . argv... |
let state = Random . State . make [ | 42 ; 987897 ; 54120 ] | |
module Crypto_samplers = Crypto_samplers . Make_finite_key_pool ( struct let algo = ` Default let size = 16 end ) |
module Michelson_base_samplers = Michelson_samplers_base . Make ( struct let parameters = let size = { Base_samplers . min = 4 ; max = 32 } in { Michelson_samplers_base . int_size = size ; string_size = size ; bytes_size = size ; } end ) |
module Data = Michelson_mcmc_samplers . Make_data_sampler ( Michelson_base_samplers ) ( Crypto_samplers ) ( struct let rng_state = state let target_size = 500 let verbosity = if verbose then ` Trace else ` Silent end ) |
let start = Unix . gettimeofday ( ) |
let generator = Data . generator ~ burn_in ( : 200 * 7 ) state |
let stop = Unix . gettimeofday ( ) |
let ( ) = Format . printf " Burn in time : % f seconds . " @ ( stop . - start ) |
let _ = for _i = 0 to 1000 do let Michelson_mcmc_samplers . { term = michelson ; typ } = generator state in if verbose then ( Format . eprintf " result . " :@ ; Format . eprintf " type : % a . " @ Test_helpers . print_script_expr typ ; Format . eprintf " % a . " @ T... |
module Request = struct include Cohttp . Request include ( Make ( IO ) : module type of Make ( IO ) with type t := t ) end |
let message = " Hello sanity " ! |
let chunk_body = [ " one " ; " " ; " " ; " bar " ; " " ] |
let ( ) = Debug . activate_debug ( ) |
let ( ) = Logs . set_level ( Some Warning ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.