parent
1aeaa794e1
commit
0ef6973457
18
src/jlib.erl
18
src/jlib.erl
|
@ -37,6 +37,7 @@
|
|||
|
||||
-export([tolower/1, term_to_base64/1, base64_to_term/1,
|
||||
decode_base64/1, encode_base64/1, ip_to_list/1,
|
||||
hex_to_bin/1, hex_to_base64/1,
|
||||
atom_to_binary/1, binary_to_atom/1, tuple_to_binary/1,
|
||||
l2i/1, i2l/1, i2l/2, expr_to_term/1, term_to_expr/1,
|
||||
queue_drop_while/2, queue_foldl/3, queue_foldr/3, queue_foreach/2]).
|
||||
|
@ -917,6 +918,23 @@ ip_to_list(undefined) ->
|
|||
ip_to_list(IP) ->
|
||||
list_to_binary(inet_parse:ntoa(IP)).
|
||||
|
||||
-spec hex_to_bin(binary()) -> binary().
|
||||
|
||||
hex_to_bin(Hex) ->
|
||||
hex_to_bin(binary_to_list(Hex), []).
|
||||
|
||||
-spec hex_to_bin(list(), list()) -> binary().
|
||||
|
||||
hex_to_bin([], Acc) ->
|
||||
list_to_binary(lists:reverse(Acc));
|
||||
hex_to_bin([H1, H2 | T], Acc) ->
|
||||
{ok, [V], []} = io_lib:fread("~16u", [H1, H2]),
|
||||
hex_to_bin(T, [V | Acc]).
|
||||
|
||||
-spec hex_to_base64(binary()) -> binary().
|
||||
|
||||
hex_to_base64(Hex) -> encode_base64(hex_to_bin(Hex)).
|
||||
|
||||
binary_to_atom(Bin) ->
|
||||
erlang:binary_to_atom(Bin, utf8).
|
||||
|
||||
|
|
|
@ -113,9 +113,9 @@ maybe_get_scram_auth(Data) ->
|
|||
case proplists:get_value(<<"iteration_count">>, Data, no_ic) of
|
||||
IC when is_float(IC) -> %% A float like 4096.0 is read
|
||||
#scram{
|
||||
storedkey = jlib:encode_base64(proplists:get_value(<<"stored_key">>, Data, <<"">>)),
|
||||
serverkey = jlib:encode_base64(proplists:get_value(<<"server_key">>, Data, <<"">>)),
|
||||
salt = jlib:encode_base64(proplists:get_value(<<"salt">>, Data, <<"">>)),
|
||||
storedkey = jlib:hex_to_base64(proplists:get_value(<<"stored_key">>, Data, <<"">>)),
|
||||
serverkey = jlib:hex_to_base64(proplists:get_value(<<"server_key">>, Data, <<"">>)),
|
||||
salt = jlib:hex_to_base64(proplists:get_value(<<"salt">>, Data, <<"">>)),
|
||||
iterationcount = round(IC)
|
||||
};
|
||||
_ -> <<"">>
|
||||
|
|
Loading…
Reference in New Issue