aboutsummaryrefslogtreecommitdiffstats
path: root/lualib
diff options
context:
space:
mode:
authorAnton Yuzhaninov <citrin+git@citrin.ru>2019-07-01 14:39:23 +0100
committerAnton Yuzhaninov <citrin+git@citrin.ru>2019-07-01 14:39:23 +0100
commit978f87970bab21475efb4e8922d85af0b6446172 (patch)
tree32cbe1615c1f0e4e99e9a0e5d6c3d066c3649d93 /lualib
parentf8004be4c94ca214cd399cdb18aa0d085abf0fd7 (diff)
downloadrspamd-978f87970bab21475efb4e8922d85af0b6446172.tar.gz
rspamd-978f87970bab21475efb4e8922d85af0b6446172.zip
[Minor] maybe_obfuscate_string changes
1. Return empty string as is (to save space). 2. Don't add ':' if prefix is empty.
Diffstat (limited to 'lualib')
-rw-r--r--lualib/lua_util.lua21
1 files changed, 13 insertions, 8 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index b5fbf78f0..d1d43564d 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -937,7 +937,8 @@ end
---[[[
-- @function lua_util.maybe_obfuscate_string(subject, settings, prefix)
--- Obfuscate string if enabled in settings. Also checks utf8 validity.
+-- Obfuscate string if enabled in settings. Also checks utf8 validity - if
+-- string is not valid utf8 then '???' is returned. Empty string returned as is.
-- Supported settings:
-- * <prefix>_privacy = false - subject privacy is off
-- * <prefix>_privacy_alg = 'blake2' - default hash-algorithm to obfuscate subject
@@ -948,20 +949,24 @@ end
exports.maybe_obfuscate_string = function(subject, settings, prefix)
local hash = require 'rspamd_cryptobox_hash'
- if subject and not rspamd_util.is_valid_utf8(subject) then
+ if not subject or subject == '' then
+ return subject
+ elseif not rspamd_util.is_valid_utf8(subject) then
subject = '???'
elseif settings[prefix .. '_privacy'] then
local hash_alg = settings[prefix .. '_privacy_alg'] or 'blake2'
local subject_hash = hash.create_specific(hash_alg, subject)
- local strip_len = settings[prefix .. '_privacy_length']
- local privacy_prefix = settings[prefix .. '_privacy_prefix'] or ''
+ local strip_len = settings[prefix .. '_privacy_length']
if strip_len then
- subject = privacy_prefix .. ':' ..
- subject_hash:hex():sub(1, strip_len)
+ subject = subject_hash:hex():sub(1, strip_len)
else
- subject = privacy_prefix .. ':' ..
- subject_hash:hex()
+ subject = subject_hash:hex()
+ end
+
+ local privacy_prefix = settings[prefix .. '_privacy_prefix']
+ if privacy_prefix and #privacy_prefix > 0 then
+ subject = privacy_prefix .. ':' .. subject
end
end