aboutsummaryrefslogtreecommitdiffstats
path: root/lualib
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-04-30 12:37:37 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-04-30 12:37:37 +0100
commitf2a5e351ef0401b37010c844dff3e4374928aaa0 (patch)
treef711f74783c704c8a3cf098d15b6e88a2a946f45 /lualib
parentf7b9b38901fe7623006f0c8dd525d3ec5b07f56b (diff)
downloadrspamd-f2a5e351ef0401b37010c844dff3e4374928aaa0.tar.gz
rspamd-f2a5e351ef0401b37010c844dff3e4374928aaa0.zip
[Minor] Selectors: Fix digests and add compatibility with blake2b used in C
Diffstat (limited to 'lualib')
-rw-r--r--lualib/lua_selectors/common.lua16
-rw-r--r--lualib/lua_selectors/extractors.lua9
2 files changed, 16 insertions, 9 deletions
diff --git a/lualib/lua_selectors/common.lua b/lualib/lua_selectors/common.lua
index e55bab84e..cb2ffc37f 100644
--- a/lualib/lua_selectors/common.lua
+++ b/lualib/lua_selectors/common.lua
@@ -16,6 +16,9 @@ limitations under the License.
local ts = require("tableshape").types
local exports = {}
+local cr_hash = require 'rspamd_cryptobox_hash'
+
+local blake2b_key = cr_hash.create_specific('blake2'):update('rspamd'):bin()
local function digest_schema()
return {ts.one_of{'hex', 'base32', 'bleach32', 'rbase32', 'base64'}:is_optional(),
@@ -25,11 +28,18 @@ end
exports.digest_schema = digest_schema
local function create_digest(data, args)
- local hash = require 'rspamd_cryptobox_hash'
+
local encoding = args[1] or 'hex'
local ht = args[2] or 'blake2'
- local h = hash:create_specific(ht):update(data)
- local s
+
+ local h, s
+
+ if ht == 'blake2' then
+ -- Hack to be compatible with various 'get_digest' methods
+ h = cr_hash.create_keyed(blake2b_key):update(data)
+ else
+ h = cr_hash.create_specific(ht):update(data)
+ end
if encoding == 'hex' then
s = h:hex()
diff --git a/lualib/lua_selectors/extractors.lua b/lualib/lua_selectors/extractors.lua
index 11728c268..e0d692135 100644
--- a/lualib/lua_selectors/extractors.lua
+++ b/lualib/lua_selectors/extractors.lua
@@ -134,12 +134,9 @@ uses any type by default)]],
['get_value'] = function(task, args)
local parts = task:get_parts() or E
local digests = {}
-
- if #args > 0 then
- for _,p in ipairs(parts) do
- if p:get_filename() then
- table.insert(digests, common.create_digest(p:get_content('raw_parsed'), args))
- end
+ for _,p in ipairs(parts) do
+ if p:get_filename() then
+ table.insert(digests, common.create_digest(p:get_content('raw_parsed'), args))
end
end