text stringlengths 0 601k |
|---|
let dh_tests = List . mapi ( fun i f -> " Assemble dh parameters " ^ string_of_int i >:: dh_assembler f ) dh_assembler_tests |
let ds_assembler ( p , res ) _ = let buf = Writer . assemble_digitally_signed p in assert_cs_eq buf res |
let ds_assembler_tests = let a = list_to_cstruct [ 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 ; 11 ; 12 ; 13 ; 14 ; 15 ] in let le = list_to_cstruct [ 0 ; 16 ] in let le2 = list_to_cstruct [ 0 ; 32 ] in let emp , empl = ( list_to_cstruct [ ] , list_to_cstruct [ 0 ; 0 ] ) in [ ( a , le <+> a ) ; ( a <+> a , le2 <+> a <+... |
let ds_tests = List . mapi ( fun i f -> " Assemble digitally signed " ^ string_of_int i >:: ds_assembler f ) ds_assembler_tests |
let ds_1_2_assembler ( sigalg , p , res ) _ = let buf = Writer . assemble_digitally_signed_1_2 sigalg p in assert_cs_eq buf res |
let ds_1_2_assembler_tests = let a = list_to_cstruct [ 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 ; 11 ; 12 ; 13 ; 14 ; 15 ] in let le = list_to_cstruct [ 0 ; 16 ] in let le2 = list_to_cstruct [ 0 ; 32 ] in let emp , empl = ( list_to_cstruct [ ] , list_to_cstruct [ 0 ; 0 ] ) in [ ( ` RSA_PKCS1_MD5 , a , list_to_cstruct... |
let ds_1_2_tests = List . mapi ( fun i f -> " Assemble digitally signed 1 . 2 " ^ string_of_int i >:: ds_1_2_assembler f ) ds_1_2_assembler_tests |
let handshake_assembler ( h , res ) _ = let res ' = list_to_cstruct res in let buf = Writer . assemble_handshake h in assert_cs_eq buf res ' |
let handshake_assembler_tests = let a_l = [ 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 ; 11 ; 12 ; 13 ; 14 ; 15 ] in let a_cs = list_to_cstruct a_l in let le = [ 0 ; 0 ; 16 ] in let le2 = [ 0 ; 0 ; 32 ] in let emp , empl = ( list_to_cstruct [ ] , [ 0 ; 0 ; 0 ] ) in Core . ( [ ( HelloRequest , [ 0 ; 0 ; 0 ; 0 ] ) ; ( Se... |
let handshake_tests = List . mapi ( fun i f -> " Assemble handshake " ^ string_of_int i >:: handshake_assembler f ) handshake_assembler_tests |
let writer_tests = version_tests @ hdr_tests @ alert_tests @ [ " CCS " >:: ccs_test ] @ dh_tests @ ds_tests @ ds_1_2_tests @ handshake_tests |
module Tree = struct type ' a t = Empty | Leaf of ' a | Node of ' a t * ' a t [ @@ deriving sexp ] sexp let to_list ( t : ' a t ) t : ' a list = let rec go acc t = match t with | Empty -> acc | Leaf x -> x :: acc | Node ( l , r ) r -> go ( go acc l ) l r in List . rev ( go [ ] t ) t let fold t ~ init ~ f = let rec go a... |
type ( ' a , ' x , ' e ) ' e t0 = ( ' a * ' x Tree . t , ' e ) ' e Result . t |
module type S = sig include Monad . S3 val of_result : ( ' a , ' e ) ' e Result . t -> ( ' a , ' x , ' e ) ' e t val write : ' x -> ( unit , ' x , ' e ) ' e t val write_all : ' x Tree . t -> ( unit , ' x , ' e ) ' e t val lift : ( ' a , ' x , ' e ) ' e t0 -> ( ' a , ' x , ' e ) ' e t val catch : ( ' a , ' x , ' e ) ' e... |
module T = struct type ( ' a , ' x , ' e ) ' e t = ( ' a * ' x Tree . t , ' e ) ' e Result . t let map ( type a b x e ) e ( t : ( a , x , e ) e t ) t ( ~ f : a -> b ) b : ( b , x , e ) e t = Result . map t ~ f ( : fun ( x , w ) w -> ( f x , w ) w ) w let return ( type a x e ) e ( x : a ) a : ( a , x , e ) e t = Ok ( x ... |
let catch ( type a b x e ) e ( t : ( a , x , e ) e t ) t ( ~ f : ( a , x , e ) e t0 -> ( b , x , e ) e t ) t : ( b , x , e ) e t = f t |
let write ( type x e ) e ( x : x ) x : ( unit , x , e ) e t = Ok ( ( ) , Leaf x ) x |
let write_all ( type x e ) e ( x : x Tree . t ) t : ( unit , x , e ) e t = Ok ( ( ) , x ) x |
let run ( t : ( ' a , ' x , ' e ) ' e t ) t : ( ' a * ' x Tree . t , ' e ) ' e Result . t = t |
let of_result ( type a e ) e ( t : ( a , e ) e Result . t ) t : ( a , _ , e ) e t = Result . map t ~ f ( : fun x -> ( x , Tree . Empty ) Empty ) Empty |
module Deferred = struct module T = struct type ( ' a , ' x , ' e ) ' e t = | Undeferred of ( ' a * ' x Tree . t , ' e ) ' e Result . t | Deferred of ( ' a * ' x Tree . t , ' e ) ' e Async . Deferred . Result . t let map ( type a b x e ) e ( t : ( a , x , e ) e t ) t ( ~ f : a -> b ) b : ( b , x , e ) e t = match t wit... |
let of_writer { Bin_prot . Type_class . write ; size } = let write buf ~ pos a = let len = Nat0 . of_int_exn ( size a ) in let pos = Nat0 . bin_write_t buf ~ pos len in write buf ~ pos a in let size a = let len = Nat0 . of_int_exn ( size a ) in Nat0 . bin_size_t len + ( ( len : Bin_prot . Nat0 . t ) :> int ) in { Bin_p... |
let of_type_class ( bin_a : _ Bin_prot . Type_class . t ) = of_writer bin_a . writer let bigstring_bin_prot s = let bigstring = Bin_prot . Utils . bin_dump Bytes . bin_writer_t s in Bin_prot . Utils . bin_dump Bigstring . Stable . V1 . bin_writer_t bigstring ; ; let bin_prot_with_length s = let writer_with_length = of_... |
let ( ) = let matrix = Array2 . create int32 c_layout _MSPACE_DIM1 _MSPACE_DIM2 in let vector = Array1 . create int32 c_layout _MSPACE1_DIM in let values = Array1 . create int32 c_layout 4 in vector . { 0 } <- Int32 . of_int ( - 1 ) ; vector . { _MSPACE1_DIM - 1 } <- Int32 . of_int ( - 1 ) ; for i = 1 to _MSPACE1_DIM -... |
module Constr = struct type t = A | B | C let get _ _ = A let put f = ignore ( f ( ) : t ) end |
module Record = struct type t = { a : int ; b : int ; c : int } let get _ _ = { a = 0 ; b = 0 ; c = 0 } let put f = ignore ( f ( ) : t ) end |
module Bool = struct type t = true | false let get _ _ = true let put f = ignore ( f ( ) : t ) end |
module List = struct type ' a t = [ ] | ( ) :: of ' a * ' a t let get _ _ = [ ] let put f = ignore ( f ( ) : int t ) end |
module Unit = struct [ @@@ warning " - redefining - unit " ] type t = ( ) let get _ _ = ( ) let put f = ignore ( f ( ( ) : unit ) : t ) end ; ; [ %% expect { | |
module Constr : sig type t = A | B | C val get : ' a -> ' b -> t val put : ( unit -> t ) -> unit end |
module Record : sig type t = { a : int ; b : int ; c : int ; } val get : ' a -> ' b -> t val put : ( unit -> t ) -> unit end |
module Bool : sig type t = true | false val get : ' a -> ' b -> t val put : ( unit -> t ) -> unit end |
module List : sig type ' a t = [ ] | ( ) :: of ' a * ' a t val get : ' a -> ' b -> ' c t val put : ( unit -> int t ) -> unit end |
module Unit : sig type t = ( ) val get : ' a -> ' b -> t val put : ( unit -> t ) -> unit end } ] | |
let ( ) = match Constr . get ( ) with | A | B | C -> ( ) ; ; [ %% expect { | ^ ' a -> Constr . t } ] | |
let ( ) = match Record . get ( ) with | { a ; _ } -> ( ) ; ; [ %% expect { | ^^^^^^^^ ' a -> Record . t } ] | |
let ( ) = match Bool . get ( ) with | true -> ( ) ; ; [ %% expect { | ^^^^ ' a -> Bool . t } ] | |
let ( ) = match Bool . get ( ) with | false -> ( ) ; ; [ %% expect { | ^^^^^ ' a -> Bool . t } ] | |
let ( ) = match List . get ( ) with | [ ] -> ( ) ; ; [ %% expect { | ^^ ' a -> ' b List . t } ] | |
let ( ) = match List . get ( ) with | _ :: _ -> ( ) ; ; [ %% expect { | ^^^^^^ ' a -> ' b List . t } ] | |
let ( ) = match Unit . get ( ) with | ( ) -> ( ) ; ; [ %% expect { | ^^ ' a -> Unit . t } ] | |
let ( ) = Constr . put A ; ; [ %% expect { | ^ unit -> Constr . t } ] | |
let ( ) = Record . put { a = 0 ; b = 0 ; c = 0 } ; ; [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^ unit -> Record . t } ] | |
let ( ) = Bool . put true ; ; [ %% expect { | ^^^^ unit -> Bool . t } ] | |
let ( ) = Bool . put false ; ; [ %% expect { | ^^^^^ unit -> Bool . t } ] | |
let ( ) = List . put [ ] ; ; [ %% expect { | ^^ unit -> int List . t } ] | |
let ( ) = List . put ( 1 :: 2 ) ; ; [ %% expect { | ^^^^^^^^ unit -> int List . t } ] | |
let ( ) = Unit . put ( ) ; ; [ %% expect { | ^^ unit -> Unit . t } ] | |
let ( ) = ignore ( ( Record . get ( ) ) . a ) ; ; [ %% expect { | ^^^^^^^^^^^^^^^ } ] | |
let ( ) = ( Record . get ( ) ) . a <- 5 ; ; [ %% expect { | ^^^^^^^^^^^^^^^ } ] | |
let ( ) = ignore { ( Record . get ( ) ) with a = 5 } ; ; [ %% expect { | ^^^^^^^^^^^^^^^ } ] | |
let foo x = Record . put { x with a = 5 } ; ; [ %% expect { | ^^^^^^^^^^^^^^^^ unit -> Record . t } ] | |
let section = Lwt_log . Section . make " wscat " |
let client uri = let open Websocket in Resolver_lwt . resolve_uri ~ uri Resolver_lwt_unix . system >>= fun endp -> let ctx = Lazy . force Conduit_lwt_unix . default_ctx in Conduit_lwt_unix . endp_to_client ~ ctx endp >>= fun client -> connect ~ ctx client uri >>= fun conn -> let close_sent = ref false in let rec react ... |
let rec react client client_id = let open Websocket in Connected_client . recv client >>= fun fr -> Lwt_log . debug_f ~ section " Client % d : % S " client_id Frame . ( show fr ) >>= fun ( ) -> match fr . opcode with | Frame . Opcode . Ping -> Connected_client . send client Frame . ( create ~ opcode : Opcode . Pong ~ c... |
let server uri = let id = ref ( - 1 ) in let echo_fun client = incr id ; let id = ! id in Lwt_log . info_f ~ section " Connection from client id % d " id >>= fun ( ) -> Lwt . catch ( fun ( ) -> react client id ) ( fun exn -> Lwt_log . error_f ~ section ~ exn " Client % d error " id >>= fun ( ) -> Lwt . fail exn ) in Re... |
let main is_server uri = if ! is_server then ( ignore @@ server uri ; fst @@ Lwt . wait ( ) ) else client uri |
let apply_loglevel = function | 2 -> Lwt_log . ( add_rule " " * Info ) | 3 -> Lwt_log . ( add_rule " " * Debug ) | _ -> ( ) |
let ( ) = let uri = ref " " in let server = ref false in let speclist = Arg . align [ ( " - s " , Arg . Set server , " Run as server " ) ; ( " - loglevel " , Arg . Int apply_loglevel , " 1 - 3 Set loglevel " ) ] in let anon_fun s = uri := s in let usage_msg = " Usage : " ^ Sys . argv . ( 0 ) ^ " < options > uri \ nOpti... |
module LwtWsIteratee = Wslib . Websockets . Wsprotocol ( Lwt ) |
let start handler = Logs_lwt . info ( fun m -> m " Starting wsproxy " ) >>= fun ( ) -> let fd_sock = Lwt_unix . stdin in let ( ) = Lwt_unix . listen fd_sock 5 in let rec loop ( ) = let ensure_close = function | [ ] -> Lwt . return_unit | fds -> Logs_lwt . warn ( fun m -> m " Closing % d excess fds " ( List . length fds... |
let proxy ( fd : Lwt_unix . file_descr ) addr protocol = let open LwtWsIteratee in let open Lwt_support in ( match protocol with | " hixie76 " -> Logs_lwt . debug ( fun m -> m " Old - style ( hixie76 ) protocol " ) >>= fun ( ) -> Lwt . return ( wsframe_old , wsunframe_old ) | " hybi10 " -> Logs_lwt . debug ( fun m -> m... |
module RX = struct let socket = Re . Str . regexp " ^/ var / run / xen / vnc [ - 0 - 9 ] " +$ let port = Re . Str . regexp " [ ^ 0 - 9 ] " +$ end |
let handler sock msg = Logs_lwt . debug ( fun m -> m " Got msg : ' % s ' " msg ) >>= fun ( ) -> match Re . Str . ( split @@ regexp " [ ] " ) : msg with | ( [ protocol ; _ ; path ] | [ protocol ; path ] ) when Re . Str . string_match RX . socket path 0 -> let addr = Unix . ADDR_UNIX path in proxy sock addr protocol | ( ... |
let lwt_reporter ( ) = let buf_fmt ~ like = let b = Buffer . create 512 in ( Fmt . with_buffer ~ like b , fun ( ) -> let m = Buffer . contents b in Buffer . reset b ; m ) in let app , app_flush = buf_fmt ~ like : Fmt . stdout in let dst , dst_flush = buf_fmt ~ like : Fmt . stderr in let reporter = Logs_fmt . reporter ~... |
let _ = Logs . set_reporter ( lwt_reporter ( ) ) ; Logs . set_level ~ all : true ( Some Logs . Info ) ; Lwt_main . run ( start handler ) |
let src = Logs . Src . create " fastws . async . wstest " |
module Log = ( val Logs . src_log src : Logs . LOG ) |
module Log_async = ( val Logs_async . src_log src : Logs_async . LOG ) |
let url_of_test url prefix i = let open Uri in with_query ' ( with_path url " runCase " ) [ ( " casetuple " , prefix ^ " . " ^ string_of_int i ) ; ( " agent " , " fastws " ) ] |
let run_test url section j = Async_uri . with_connection url ( fun { r ; w ; _ } -> Fastws_async . with_connection ( url_of_test url section j ) r w Fn . id Fn . id ( fun r w -> Pipe . iter r ~ f ( : fun ( fr : Frame . t ) -> Pipe . write w fr ) ) ) |
let main url section tests = Random . self_init ( ) ; Deferred . Or_error . List . iter ( List . concat tests ) ~ f ( : fun x -> Fastws_async . Raw . to_or_error ( run_test url section x ) ) |
let url_cmd = Command . Arg_type . create Uri . of_string |
let pp_header ppf ( l , _ ) = let now = Time_ns . now ( ) in Format . fprintf ppf " % a [ % a ] " Time_ns . pp now Logs . pp_level l |
let range_of_string s = match String . rsplit2 s ~ on ' ' :- with | None -> [ Int . of_string s ] | Some ( a , b ) -> let a = Int . of_string a in let b = Int . of_string b in List . range ~ start ` : inclusive ~ stop ` : inclusive a b |
let range = let open Command . Arg_type in comma_separated ( map Export . string ~ f : range_of_string ) |
let ( ) = Command . async_or_error ~ summary " : Autobahn test client " ( let open Command . Let_syntax in [ % map_open let ( ) = Logs_async_reporter . set_level_via_param [ ] and url = anon ( " url " %: url_cmd ) and section = anon ( " section " %: string ) and tests = anon ( " tests " %: range ) in fun ( ) -> Logs . ... |
module type S = sig type ' a t val create : unit -> ' a t val push : ' a t -> ' a -> unit val pop : ' a t -> ' a val steal : ' a t -> ' a end |
module CArray = struct type ' a t = ' a array let rec log2 n = if n <= 1 then 0 else 1 + ( log2 ( n asr 1 ) ) let create sz v = assert ( 0 < sz && sz = Int . shift_left 1 ( log2 sz ) ) ; assert ( Int . logand sz ( sz - 1 ) == 0 ) ; Array . make sz v let size t = Array . length t [ @@ inline ] let mask t = size t - 1 [ ... |
module M : S = struct let min_size = 32 let shrink_const = 3 type ' a t = { top : int Atomic . t ; bottom : int Atomic . t ; tab : ' a ref CArray . t Atomic . t ; mutable next_shrink : int ; } let create ( ) = { top = Atomic . make 1 ; bottom = Atomic . make 1 ; tab = Atomic . make ( CArray . create min_size ( Obj . ma... |
type codepoint = | Point of int | Malformed |
type ' a folder = ' a -> int -> codepoint -> ' a |
let needed_bytes c = if 0x00 <= c && c <= 0x7F then 1 else if 0xC2 <= c && c <= 0xDF then 2 else if 0xE0 <= c && c <= 0xEF then 3 else if 0xF0 <= c && c <= 0xF4 then 4 else 0 |
let unsafe_char s i = Char . code ( Bytes . unsafe_get s i ) |
let codepoint s i = function | 1 -> unsafe_char s i | 2 -> let b0 = unsafe_char s i in let b1 = unsafe_char s ( i + 1 ) in ( ( b0 land 0x1F ) lsl 6 ) lor ( b1 land 0x3F ) | 3 -> let b0 = unsafe_char s ( i ) in let b1 = unsafe_char s ( i + 1 ) in let b2 = unsafe_char s ( i + 2 ) in ( ( b0 land 0x0F ) lsl 12 ) lor ( ( b1... |
let fold_wtf_8 ( ? pos = 0 ) ? len f acc s = let rec loop acc f s i l = if i = l then acc else let need = needed_bytes ( unsafe_char s i ) in if need = 0 then ( loop [ @ tailcall ] ) ( f acc i Malformed ) f s ( i + 1 ) l else let rem = l - i in if rem < need then f acc i Malformed else ( loop [ @ tailcall ] ) ( f acc i... |
let add_wtf_8 buf code = let [ @ inline ] w byte = Buffer . add_char buf ( Char . unsafe_chr byte ) in if code >= 0x10000 then begin w ( 0xf0 lor ( code lsr 18 ) ) ; w ( 0x80 lor ( ( code lsr 12 ) land 0x3F ) ) ; w ( 0x80 lor ( ( code lsr 6 ) land 0x3F ) ) ; w ( 0x80 lor ( code land 0x3F ) ) end else if code >= 0x800 t... |
type json = Yojson . Safe . t [ @@ deriving of_yojson ] |
type hex = string [ @@ deriving eq ] |
let pp_hex fmt s = let ( ` Hex h ) = Hex . of_string s in Format . pp_print_string fmt h |
let hex_of_yojson json = let padded s = if String . length s mod 2 = 0 then s else " 0 " ^ s in match [ % of_yojson : string ] json with | Ok s -> Ok ( Hex . to_string ( ` Hex ( padded s ) ) ) | Error _ as e -> e |
type test_result = Valid | Acceptable | Invalid [ @@ deriving show ] |
let test_result_of_yojson = function | ` String " valid " -> Ok Valid | ` String " acceptable " -> Ok Acceptable | ` String " invalid " -> Ok Invalid | _ -> Error " test_result " |
type ecdh_test = { tcId : int ; comment : string ; curve : json option ; [ @ yojson . default None ] public : hex ; private_ : hex ; [ @ yojson . key " private " ] shared : hex ; result : test_result ; flags : string list ; } |
let has_ignored_flag test ~ ignored_flags = List . exists ( fun ignored_flag -> List . mem ignored_flag test . flags ) ignored_flags |
type ecdh_test_group = { curve : string ; tests : ecdh_test list ; encoding : json option ; [ @ yojson . default None ] type_ : json option ; [ @ yojson . default None ] [ @ yojson . key " type " ] } |
type ecdsa_key = { curve : string ; keySize : int ; type_ : json ; [ @ yojson . key " type " ] uncompressed : hex ; wx : hex ; wy : hex ; } |
type dsa_test = { tcId : int ; comment : string ; msg : hex ; sig_ : hex ; [ @ yojson . key " sig " ] result : test_result ; flags : string list ; } |
type ecdsa_test_group = { key : ecdsa_key ; keyDer : string ; keyPem : string ; sha : string ; tests : dsa_test list ; type_ : json option ; [ @ yojson . default None ] [ @ yojson . key " type " ] } |
type eddsa_key = { curve : string ; keySize : int ; pk : hex ; sk : hex ; type_ : json ; [ @ yojson . key " type " ] } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.