Explorar o código

chore(rule-engine): compatible with the lower case hash string

JianBo He %!s(int64=4) %!d(string=hai) anos
pai
achega
496e5381fb
Modificáronse 4 ficheiros con 16 adicións e 10 borrados
  1. 2 2
      apps/emqx_rule_engine/src/emqx_rule_funcs.erl
  2. 1 1
      src/emqx_guid.erl
  3. 12 6
      src/emqx_misc.erl
  4. 1 1
      src/emqx_tracer.erl

+ 2 - 2
apps/emqx_rule_engine/src/emqx_rule_funcs.erl

@@ -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

+ 1 - 1
src/emqx_guid.erl

@@ -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).

+ 12 - 6
src/emqx_misc.erl

@@ -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()).
-bin2hexstr(B) when is_binary(B) ->
-    << <<(int2hexchar(H)), (int2hexchar(L))>> || <<H:4, L:4>> <= B>>.
+-spec(bin2hexstr_A_F(binary()) -> binary()).
+bin2hexstr_A_F(B) when is_binary(B) ->
+    << <<(int2hexchar(H, upper)), (int2hexchar(L, upper))>> || <<H:4, L:4>> <= 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))>> || <<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) ->

+ 1 - 1
src/emqx_tracer.erl

@@ -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)).