aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_util.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r--lualib/lua_util.lua22
1 files changed, 17 insertions, 5 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 8f24b2871..79c031b3c 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -1207,26 +1207,38 @@ end
---[[[
-- @function lua_util.table_digest(t)
--- Returns hash of all values if t[1] is string or all keys otherwise
+-- Returns hash of all values if t[1] is string or all keys/values otherwise
-- @param {table} t input array or map
-- @return {string} base32 representation of blake2b hash of all strings
--]]]
-exports.table_digest = function(t)
+local function table_digest(t)
local cr = require "rspamd_cryptobox_hash"
local h = cr.create()
if t[1] then
for _,e in ipairs(t) do
- h:update(tostring(e))
+ if type(e) == 'table' then
+ h:update(table_digest(e))
+ else
+ h:update(tostring(e))
+ end
end
else
- for k,_ in pairs(t) do
- h:update(k)
+ for k,v in pairs(t) do
+ h:update(tostring(k))
+
+ if type(v) == 'string' then
+ h:update(v)
+ elseif type(v) == 'table' then
+ h:update(table_digest(v))
+ end
end
end
return h:base32()
end
+exports.table_digest = table_digest
+
---[[[
-- @function lua_util.toboolean(v)
-- Converts a string or a number to boolean