Get rid of deprecated crypto functions

This commit is contained in:
Evgeniy Khramtsov 2017-08-17 19:32:15 +03:00
parent b8d2a72333
commit 6e20e9bcf9
4 changed files with 18 additions and 2 deletions

View File

@ -92,6 +92,7 @@
{if_var_true, elixir, {d, 'ELIXIR_ENABLED'}},
{if_var_true, erlang_deprecated_types, {d, 'ERL_DEPRECATED_TYPES'}},
{if_have_fun, {crypto, strong_rand_bytes, 1}, {d, 'STRONG_RAND_BYTES'}},
{if_have_fun, {rand, uniform, 1}, {d, 'RAND_UNIFORM'}},
{if_have_fun, {gb_sets, iterator_from, 2}, {d, 'GB_SETS_ITERATOR_FROM'}},
{if_have_fun, {public_key, short_name_hash, 1}, {d, 'SHORT_NAME_HASH'}},
{if_var_true, hipe, native},

View File

@ -374,7 +374,7 @@ mk_bounce_error(_Lang, _State) ->
-spec get_delay() -> non_neg_integer().
get_delay() ->
MaxDelay = ejabberd_config:get_option(s2s_max_retry_delay, 300),
crypto:rand_uniform(1, MaxDelay).
randoms:uniform(MaxDelay).
-spec set_idle_timeout(state()) -> state().
set_idle_timeout(#{on_route := send, server := LServer} = State) ->

View File

@ -658,7 +658,7 @@ make_rand_string(S, N) -> make_rand_string([make_rand_char() | S], N - 1).
-spec make_rand_char() -> char().
make_rand_char() ->
map_int_to_char(crypto:rand_uniform(0, 62)).
map_int_to_char(randoms:uniform(0, 61)).
-spec map_int_to_char(0..61) -> char().

View File

@ -32,6 +32,20 @@
-define(THRESHOLD, 16#10000000000000000).
-ifdef(RAND_UNIFORM).
get_string() ->
R = rand:uniform(?THRESHOLD),
integer_to_binary(R).
uniform() ->
rand:uniform().
uniform(N) ->
rand:uniform(N).
uniform(N, M) ->
rand:uniform(M-N+1) + N-1.
-else.
get_string() ->
R = crypto:rand_uniform(0, ?THRESHOLD),
integer_to_binary(R).
@ -44,6 +58,7 @@ uniform(N) ->
uniform(N, M) ->
crypto:rand_uniform(N, M+1).
-endif.
-ifdef(STRONG_RAND_BYTES).
bytes(N) ->