commit d4c4a09: [Minor] Lua_util: Add table_digest function
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Jul 5 15:28:05 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-07-05 13:55:12 +0100
URL: https://github.com/rspamd/rspamd/commit/d4c4a09b116c48f865dbcc6787d7fa3079d7d0a3
[Minor] Lua_util: Add table_digest function
---
lualib/lua_util.lua | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 7092aa3de..432f55c6a 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -1090,4 +1090,26 @@ exports.distance_sorted = function(t1, t2)
return ndiff
end
+---[[[
+-- @function lua_util.table_digest(t)
+-- Returns hash of all values if t[1] is string or all keys otherwise
+-- @param {table} t input array or map
+-- @return {string} base32 representation of blake2b hash of all strings
+--]]]
+exports.table_digest = function(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))
+ end
+ else
+ for k,_ in pairs(t) do
+ h:update(k)
+ end
+ end
+ return h:base32()
+end
+
return exports
More information about the Commits
mailing list