From: Vsevolod Stakhov Date: Fri, 5 Jul 2019 12:55:12 +0000 (+0100) Subject: [Minor] Lua_util: Add table_digest function X-Git-Tag: 2.0~655 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d4c4a09b116c48f865dbcc6787d7fa3079d7d0a3;p=thirdparty%2Frspamd.git [Minor] Lua_util: Add table_digest function --- diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index 7092aa3de9..432f55c6aa 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