chore(rule-engine): compatible with the lower case hash string
This commit is contained in:
parent
b8c7c9c60b
commit
496e5381fb
|
@ -512,7 +512,7 @@ map(Data) ->
|
||||||
emqx_rule_utils:map(Data).
|
emqx_rule_utils:map(Data).
|
||||||
|
|
||||||
bin2hexstr(Bin) when is_binary(Bin) ->
|
bin2hexstr(Bin) when is_binary(Bin) ->
|
||||||
emqx_misc:bin2hexstr(Bin).
|
emqx_misc:bin2hexstr_A_F(Bin).
|
||||||
|
|
||||||
hexstr2bin(Str) when is_binary(Str) ->
|
hexstr2bin(Str) when is_binary(Str) ->
|
||||||
emqx_misc:hexstr2bin(Str).
|
emqx_misc:hexstr2bin(Str).
|
||||||
|
@ -774,7 +774,7 @@ sha256(S) when is_binary(S) ->
|
||||||
hash(sha256, S).
|
hash(sha256, S).
|
||||||
|
|
||||||
hash(Type, Data) ->
|
hash(Type, Data) ->
|
||||||
emqx_misc:bin2hexstr(crypto:hash(Type, Data)).
|
emqx_misc:bin2hexstr_a_f(crypto:hash(Type, Data)).
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% Data encode and decode Funcs
|
%% Data encode and decode Funcs
|
||||||
|
|
|
@ -137,7 +137,7 @@ npid() ->
|
||||||
NPid.
|
NPid.
|
||||||
|
|
||||||
to_hexstr(I) when byte_size(I) =:= 16 ->
|
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 ->
|
from_hexstr(S) when byte_size(S) =:= 32 ->
|
||||||
emqx_misc:hexstr2bin(S).
|
emqx_misc:hexstr2bin(S).
|
||||||
|
|
|
@ -45,7 +45,8 @@
|
||||||
, index_of/2
|
, index_of/2
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([ bin2hexstr/1
|
-export([ bin2hexstr_A_F/1
|
||||||
|
, bin2hexstr_a_f/1
|
||||||
, hexstr2bin/1
|
, hexstr2bin/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
@ -237,12 +238,17 @@ index_of(E, I, [E|_]) ->
|
||||||
index_of(E, I, [_|L]) ->
|
index_of(E, I, [_|L]) ->
|
||||||
index_of(E, I+1, L).
|
index_of(E, I+1, L).
|
||||||
|
|
||||||
-spec(bin2hexstr(binary()) -> binary()).
|
-spec(bin2hexstr_A_F(binary()) -> binary()).
|
||||||
bin2hexstr(B) when is_binary(B) ->
|
bin2hexstr_A_F(B) when is_binary(B) ->
|
||||||
<< <<(int2hexchar(H)), (int2hexchar(L))>> || <<H:4, L:4>> <= B>>.
|
<< <<(int2hexchar(H, upper)), (int2hexchar(L, upper))>> || <<H:4, L:4>> <= B>>.
|
||||||
|
|
||||||
int2hexchar(I) when I >= 0 andalso I < 10 -> I + $0;
|
-spec(bin2hexstr_a_f(binary()) -> binary()).
|
||||||
int2hexchar(I) -> I - 10 + $A.
|
bin2hexstr_a_f(B) when is_binary(B) ->
|
||||||
|
<< <<(int2hexchar(H, lower)), (int2hexchar(L, lower))>> || <<H:4, L:4>> <= 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()).
|
-spec(hexstr2bin(binary()) -> binary()).
|
||||||
hexstr2bin(B) when is_binary(B) ->
|
hexstr2bin(B) when is_binary(B) ->
|
||||||
|
|
|
@ -161,4 +161,4 @@ handler_name(Bin) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
hashstr(Bin) ->
|
hashstr(Bin) ->
|
||||||
binary_to_list(emqx_misc:bin2hexstr(Bin)).
|
binary_to_list(emqx_misc:bin2hexstr_A_F(Bin)).
|
||||||
|
|
Loading…
Reference in New Issue