diff --git a/.gitignore b/.gitignore index bb59f19..0f0aca0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ *.swp *.beam *.dump +_build/* +rebar.lock diff --git a/Makefile b/Makefile index 33601c7..86bc73d 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ PREFIX:=../ DEST:=$(PREFIX)$(PROJECT) -REBAR=./rebar +REBAR=./rebar3 .PHONY: all edoc test clean build_plt dialyzer app diff --git a/rebar b/rebar deleted file mode 100755 index 0d1980b..0000000 Binary files a/rebar and /dev/null differ diff --git a/rebar3 b/rebar3 new file mode 100755 index 0000000..f0b1ba7 Binary files /dev/null and b/rebar3 differ diff --git a/src/mochitemp.erl b/src/mochitemp.erl index bd3c965..0128dce 100644 --- a/src/mochitemp.erl +++ b/src/mochitemp.erl @@ -104,8 +104,15 @@ rngchars(0) -> rngchars(N) -> [rngchar() | rngchars(N - 1)]. + +-ifdef(crypto_compatibility). rngchar() -> rngchar(crypto:rand_uniform(0, tuple_size(?SAFE_CHARS))). +-else. +rngchar() -> + rngchar(rand:uniform(tuple_size(?SAFE_CHARS)) - 1). +-endif. + rngchar(C) -> element(1 + C, ?SAFE_CHARS). diff --git a/src/mochiweb_html.erl b/src/mochiweb_html.erl index 3fd93d0..734eb6d 100644 --- a/src/mochiweb_html.erl +++ b/src/mochiweb_html.erl @@ -23,7 +23,7 @@ -module(mochiweb_html). -export([tokens/1, parse/1, parse_tokens/1, to_tokens/1, escape/1, escape_attr/1, to_html/1]). --compile([export_all]). + -ifdef(TEST). -export([destack/1, destack/2, is_singleton/1]). -endif. diff --git a/src/mochiweb_multipart.erl b/src/mochiweb_multipart.erl index 1d18ae2..f349838 100644 --- a/src/mochiweb_multipart.erl +++ b/src/mochiweb_multipart.erl @@ -56,7 +56,7 @@ parts_to_body([{Start, End, Body}], ContentType, Size) -> {HeaderList, Body}; parts_to_body(BodyList, ContentType, Size) when is_list(BodyList) -> parts_to_multipart_body(BodyList, ContentType, Size, - mochihex:to_hex(crypto:rand_bytes(8))). + mochihex:to_hex(crypto:strong_rand_bytes(8))). %% @spec parts_to_multipart_body([bodypart()], ContentType::string(), %% Size::integer(), Boundary::string()) -> @@ -315,8 +315,7 @@ find_boundary(Prefix, Data) -> -include_lib("eunit/include/eunit.hrl"). ssl_cert_opts() -> - EbinDir = filename:dirname(code:which(?MODULE)), - CertDir = filename:join([EbinDir, "..", "support", "test-materials"]), + CertDir = filename:join(["support", "test-materials"]), CertFile = filename:join(CertDir, "test_ssl_cert.pem"), KeyFile = filename:join(CertDir, "test_ssl_key.pem"), [{certfile, CertFile}, {keyfile, KeyFile}]. diff --git a/src/mochiweb_session.erl b/src/mochiweb_session.erl index 1d4df35..546b347 100644 --- a/src/mochiweb_session.erl +++ b/src/mochiweb_session.erl @@ -141,7 +141,7 @@ gen_hmac(ExpirationTime, Data, SessionKey, Key) -> -else. -spec encrypt_data(binary(), binary()) -> binary(). encrypt_data(Data, Key) -> - IV = crypto:rand_bytes(16), + IV = crypto:strong_rand_bytes(16), Crypt = crypto:block_encrypt(aes_cfb128, Key, IV, Data), <>. diff --git a/src/mochiweb_websocket.erl b/src/mochiweb_websocket.erl index ecf4fb6..bb36350 100644 --- a/src/mochiweb_websocket.erl +++ b/src/mochiweb_websocket.erl @@ -28,7 +28,7 @@ -export([loop/5, upgrade_connection/2, request/5]). -export([send/3]). -ifdef(TEST). --compile(export_all). +-compile([export_all, nowarn_export_all]). -endif. loop(Socket, Body, State, WsVersion, ReplyChannel) -> diff --git a/test/mochiweb_base64url_tests.erl b/test/mochiweb_base64url_tests.erl index 69f276a..8ca98a8 100644 --- a/test/mochiweb_base64url_tests.erl +++ b/test/mochiweb_base64url_tests.erl @@ -11,8 +11,8 @@ id(X) -> binary_to_list(mochiweb_base64url:encode(binary_to_list(X))))). random_binary(Short,Long) -> - << <<(random:uniform(256) - 1)>> - || _ <- lists:seq(1, Short + random:uniform(1 + Long - Short) - 1) >>. + << <<(rand:uniform(256) - 1)>> + || _ <- lists:seq(1, Short + rand:uniform(1 + Long - Short) - 1) >>. empty_test() -> id(<<>>). diff --git a/test/mochiweb_http_tests.erl b/test/mochiweb_http_tests.erl index 9e8f183..24637b8 100644 --- a/test/mochiweb_http_tests.erl +++ b/test/mochiweb_http_tests.erl @@ -126,7 +126,7 @@ build_headers(Count, Size) -> AllowedChars = ["a", "b", "c", "1"], CharFun = fun(_I, Acc) -> - C = lists:nth(random:uniform(length(AllowedChars)), AllowedChars), + C = lists:nth(rand:uniform(length(AllowedChars)), AllowedChars), [C|Acc] end, FullString = lists:reverse(lists:foldl(CharFun, [], lists:seq(1, Size))), diff --git a/test/mochiweb_test_util.erl b/test/mochiweb_test_util.erl index 2fbf14f..7c1f20a 100644 --- a/test/mochiweb_test_util.erl +++ b/test/mochiweb_test_util.erl @@ -4,9 +4,9 @@ -include("mochiweb_test_util.hrl"). -include_lib("eunit/include/eunit.hrl"). + ssl_cert_opts() -> - EbinDir = filename:dirname(code:which(?MODULE)), - CertDir = filename:join([EbinDir, "..", "support", "test-materials"]), + CertDir = filename:join(["support", "test-materials"]), CertFile = filename:join(CertDir, "test_ssl_cert.pem"), KeyFile = filename:join(CertDir, "test_ssl_key.pem"), [{certfile, CertFile}, {keyfile, KeyFile}]. diff --git a/test/mochiweb_tests.erl b/test/mochiweb_tests.erl index 209971b..204525e 100644 --- a/test/mochiweb_tests.erl +++ b/test/mochiweb_tests.erl @@ -138,7 +138,7 @@ do_POST(Transport, Size, Times) -> end, TestReqs = [begin Path = "/stuff/" ++ integer_to_list(N), - Body = crypto:rand_bytes(Size), + Body = crypto:strong_rand_bytes(Size), #treq{path=Path, body=Body, xreply=Body} end || N <- lists:seq(1, Times)], ClientFun = new_client_fun('POST', TestReqs),