diff --git a/apps/emqx_rule_engine/src/emqx_rule_funcs.erl b/apps/emqx_rule_engine/src/emqx_rule_funcs.erl index 3e41b2520..7c939e93d 100644 --- a/apps/emqx_rule_engine/src/emqx_rule_funcs.erl +++ b/apps/emqx_rule_engine/src/emqx_rule_funcs.erl @@ -512,7 +512,7 @@ map(Data) -> emqx_rule_utils:map(Data). bin2hexstr(Bin) when is_binary(Bin) -> - emqx_misc:bin2hexstr(Bin). + emqx_misc:bin2hexstr_A_F(Bin). hexstr2bin(Str) when is_binary(Str) -> emqx_misc:hexstr2bin(Str). @@ -774,7 +774,7 @@ sha256(S) when is_binary(S) -> hash(sha256, S). hash(Type, Data) -> - emqx_misc:bin2hexstr(crypto:hash(Type, Data)). + emqx_misc:bin2hexstr_a_f(crypto:hash(Type, Data)). %%------------------------------------------------------------------------------ %% Data encode and decode Funcs diff --git a/src/emqx_guid.erl b/src/emqx_guid.erl index 7a7657ad1..97e023d8c 100644 --- a/src/emqx_guid.erl +++ b/src/emqx_guid.erl @@ -137,7 +137,7 @@ npid() -> NPid. to_hexstr(I) when byte_size(I) =:= 16 -> - emqx_misc:bin2hexstr(I). + emqx_misc:bin2hexstr_A_F(I). from_hexstr(S) when byte_size(S) =:= 32 -> emqx_misc:hexstr2bin(S). diff --git a/src/emqx_misc.erl b/src/emqx_misc.erl index a96261f74..bf6bcd4a6 100644 --- a/src/emqx_misc.erl +++ b/src/emqx_misc.erl @@ -45,7 +45,8 @@ , index_of/2 ]). --export([ bin2hexstr/1 +-export([ bin2hexstr_A_F/1 + , bin2hexstr_a_f/1 , hexstr2bin/1 ]). @@ -237,12 +238,17 @@ index_of(E, I, [E|_]) -> index_of(E, I, [_|L]) -> index_of(E, I+1, L). --spec(bin2hexstr(binary()) -> binary()). -bin2hexstr(B) when is_binary(B) -> - << <<(int2hexchar(H)), (int2hexchar(L))>> || <> <= B>>. +-spec(bin2hexstr_A_F(binary()) -> binary()). +bin2hexstr_A_F(B) when is_binary(B) -> + << <<(int2hexchar(H, upper)), (int2hexchar(L, upper))>> || <> <= B>>. -int2hexchar(I) when I >= 0 andalso I < 10 -> I + $0; -int2hexchar(I) -> I - 10 + $A. +-spec(bin2hexstr_a_f(binary()) -> binary()). +bin2hexstr_a_f(B) when is_binary(B) -> + << <<(int2hexchar(H, lower)), (int2hexchar(L, lower))>> || <> <= B>>. + +int2hexchar(I, _) when I >= 0 andalso I < 10 -> I + $0; +int2hexchar(I, upper) -> I - 10 + $A; +int2hexchar(I, lower) -> I - 10 + $a. -spec(hexstr2bin(binary()) -> binary()). hexstr2bin(B) when is_binary(B) -> diff --git a/src/emqx_tracer.erl b/src/emqx_tracer.erl index 871c3dc81..ef7e73a8d 100644 --- a/src/emqx_tracer.erl +++ b/src/emqx_tracer.erl @@ -161,4 +161,4 @@ handler_name(Bin) -> end. hashstr(Bin) -> - binary_to_list(emqx_misc:bin2hexstr(Bin)). + binary_to_list(emqx_misc:bin2hexstr_A_F(Bin)).