end.
hex(S) ->
- p1_sha:to_hexlist(S).
+ str:to_hexlist(S).
proplists_get_bin_value(Key, Pairs, Default) ->
case proplists:get_value(Key, Pairs, Default) of
is_valid_key(<<"">>, <<"">>) -> true;
is_valid_key(PrevKey, Key) ->
- p1_sha:sha(Key) == PrevKey.
+ str:sha(Key) == PrevKey.
is_overactivity(undefined) -> false;
is_overactivity(PrevPoll) ->
end,
{Status, Reason, ?HEADER(CType), <<"">>}.
-make_sid() -> p1_sha:sha(randoms:get_string()).
+make_sid() -> str:sha(randoms:get_string()).
-compile({no_auto_import, [{min, 2}]}).
{ok, Type, Key, Image} ->
Id = <<(randoms:get_string())/binary>>,
JID = jid:encode(From),
- CID = <<"sha1+", (p1_sha:sha(Image))/binary, "@bob.xmpp.org">>,
+ CID = <<"sha1+", (str:sha(Image))/binary, "@bob.xmpp.org">>,
Data = #bob_data{cid = CID, 'max-age' = 0, type = Type,
data = Image},
Fs = [mk_field(hidden, <<"FORM_TYPE">>, ?NS_CAPTCHA),
case create_image(Limiter) of
{ok, Type, Key, Image} ->
Id = <<(randoms:get_string())/binary>>,
- CID = <<"sha1+", (p1_sha:sha(Image))/binary, "@bob.xmpp.org">>,
+ CID = <<"sha1+", (str:sha(Image))/binary, "@bob.xmpp.org">>,
Data = #bob_data{cid = CID, 'max-age' = 0, type = Type, data = Image},
HelpTxt = translate:translate(Lang,
<<"If you don't see the CAPTCHA image here, "
UnixTime = p1_time_compat:system_time(seconds),
SharedKey = case erlang:get_cookie() of
nocookie ->
- p1_sha:sha(randoms:get_string());
+ str:sha(randoms:get_string());
Cookie ->
- p1_sha:sha(jlib:atom_to_binary(Cookie))
+ str:sha(jlib:atom_to_binary(Cookie))
end,
State2 = set_option({node_start, global}, UnixTime, State1),
State3 = set_option({shared_key, global}, SharedKey, State2),
fun({H, Os}, D) ->
P = proplists:get_value(
password, Os,
- p1_sha:sha(randoms:bytes(20))),
+ str:sha(randoms:bytes(20))),
dict:store(H, P, D)
end, dict:new(), HOpts);
false ->
Pass = proplists:get_value(
password, Opts,
- p1_sha:sha(randoms:bytes(20))),
+ str:sha(randoms:bytes(20))),
dict:from_list([{global, Pass}])
end,
CheckFrom = gen_mod:get_opt(check_from, Opts,
-spec make_user_string(jid(), sha1 | node) -> binary().
make_user_string(#jid{luser = U, lserver = S}, sha1) ->
- p1_sha:sha(<<U/binary, $@, S/binary>>);
+ str:sha(<<U/binary, $@, S/binary>>);
make_user_string(#jid{luser = U}, node) ->
re:replace(U, <<"[^a-zA-Z0-9_.-]">>, <<$_>>, [global, {return, binary}]).
resource = R}]} = IQ) ->
P = if is_binary(P0) -> P0; true -> <<>> end,
D = if is_binary(D0) -> D0; true -> <<>> end,
- DGen = fun (PW) -> p1_sha:sha(<<StreamID/binary, PW/binary>>) end,
+ DGen = fun (PW) -> str:sha(<<StreamID/binary, PW/binary>>) end,
JID = jid:make(U, Server, R),
case JID /= error andalso
acl:access_matches(Access,
LFrom = jid:tolower(BareFrom),
LTo = jid:tolower(jid:remove_resource(To)),
Participant = #mix_participant{jid = BareFrom},
- ItemID = p1_sha:sha(jid:encode(LFrom)),
+ ItemID = str:sha(jid:encode(LFrom)),
mod_pubsub:publish_item(
LTo, To#jid.lserver, ?NS_MIX_NODES_PARTICIPANTS,
From, ItemID, [xmpp:encode(Participant)]).
delete_participant(From, To) ->
LFrom = jid:tolower(jid:remove_resource(From)),
- ItemID = p1_sha:sha(jid:encode(LFrom)),
+ ItemID = str:sha(jid:encode(LFrom)),
delete_presence(From, To),
delete_item(From, To, ?NS_MIX_NODES_PARTICIPANTS, ItemID).
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
process_muc_unique(#iq{from = From, type = get,
sub_els = [#muc_unique{}]} = IQ) ->
- Name = p1_sha:sha(term_to_binary([From, p1_time_compat:timestamp(),
+ Name = str:sha(term_to_binary([From, p1_time_compat:timestamp(),
randoms:get_string()])),
xmpp:make_iq_result(IQ, #muc_unique{name = Name}).
Node = ejabberd_cluster:get_node_by_id(To#jid.lresource),
Target = jid:encode(jid:tolower(TargetJID)),
Initiator = jid:encode(jid:tolower(InitiatorJID)),
- SHA1 = p1_sha:sha(<<SID/binary, Initiator/binary, Target/binary>>),
+ SHA1 = str:sha(<<SID/binary, Initiator/binary, Target/binary>>),
Mod = gen_mod:ram_db_mod(global, mod_proxy65),
MaxConnections = max_connections(ServerHost),
case Mod:activate_stream(SHA1, Initiator, MaxConnections, Node) of
xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
roster_hash(Items) ->
- p1_sha:sha(term_to_binary(lists:sort([R#roster{groups =
+ str:sha(term_to_binary(lists:sort([R#roster{groups =
lists:sort(Grs)}
|| R = #roster{groups = Grs}
<- Items]))).
write_roster_version(LUser, LServer, true).
write_roster_version(LUser, LServer, InTransaction) ->
- Ver = p1_sha:sha(term_to_binary(p1_time_compat:unique_integer())),
+ Ver = str:sha(term_to_binary(p1_time_compat:unique_integer())),
Mod = gen_mod:db_mod(LServer, ?MODULE),
Mod:write_roster_version(LUser, LServer, InTransaction, Ver),
Ver.
-spec make_key(binary(), binary(), binary()) -> binary().
make_key(From, To, StreamID) ->
Secret = ejabberd_config:get_option(shared_key, fun(V) -> V end),
- p1_sha:to_hexlist(
- crypto:hmac(sha256, p1_sha:to_hexlist(crypto:hash(sha256, Secret)),
+ str:to_hexlist(
+ crypto:hmac(sha256, str:to_hexlist(crypto:hash(sha256, Secret)),
[To, " ", From, " ", StreamID])).
-spec send_verify_request(ejabberd_s2s_out:state()) -> ejabberd_s2s_out:state().
FromTag = esip:get_param(<<"tag">>, FParams),
CallID = esip:get_hdr('call-id', Hdrs),
SharedKey = ejabberd_config:get_option(shared_key, fun(V) -> V end),
- p1_sha:sha([SharedKey, LFUser, LFServer, LTUser, LTServer,
+ str:sha([SharedKey, LFUser, LFServer, LTUser, LTServer,
FromTag, CallID, TS]).
is_signed_by_me(TS_Sign, Hdrs) ->
<<>> -> remove_xupdate(LUser, LServer);
BinVal ->
add_xupdate(LUser, LServer,
- p1_sha:sha(jlib:decode_base64(BinVal)))
+ str:sha(jlib:decode_base64(BinVal)))
end,
ejabberd_sm:force_update_presence(US).
prefix/2,
suffix/2,
format/2,
- to_integer/1]).
+ to_integer/1,
+ sha/1,
+ to_hexlist/1]).
%%%===================================================================
%%% API
format(Format, Args) ->
iolist_to_binary(io_lib:format(Format, Args)).
+
+-spec sha(binary()) -> binary().
+
+sha(Text) ->
+ Bin = crypto:hash(sha, Text),
+ to_hexlist(Bin).
+
+-spec to_hexlist(binary()) -> binary().
+
+to_hexlist(S) when is_list(S) ->
+ to_hexlist(iolist_to_binary(S));
+to_hexlist(Bin) when is_binary(Bin) ->
+ << <<(digit_to_xchar(N div 16)), (digit_to_xchar(N rem 16))>> || <<N>> <= Bin >>.
+
%%%===================================================================
%%% Internal functions
%%%===================================================================
[];
join_s([H|T], Sep) ->
[H, [[Sep, X] || X <- T]].
+
+digit_to_xchar(D) when (D >= 0) and (D < 10) -> D + $0;
+digit_to_xchar(D) -> D + $a - 10.
{false, _} ->
false;
{Password, _} ->
- p1_sha:sha(<<StreamID/binary, Password/binary>>) == Digest
+ str:sha(<<StreamID/binary, Password/binary>>) == Digest
end,
case AuthRes of
true ->