commit 978f879: [Minor] maybe_obfuscate_string changes
Anton Yuzhaninov
citrin+git at citrin.ru
Mon Jul 1 16:49:04 UTC 2019
Author: Anton Yuzhaninov
Date: 2019-07-01 14:39:23 +0100
URL: https://github.com/rspamd/rspamd/commit/978f87970bab21475efb4e8922d85af0b6446172
[Minor] maybe_obfuscate_string changes
1. Return empty string as is (to save space).
2. Don't add ':' if prefix is empty.
---
lualib/lua_util.lua | 21 +++++++++++++--------
1 file 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
More information about the Commits
mailing list