aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-12-21 20:21:06 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-12-21 20:21:06 +0000
commitdd2b7b4c24e34d77382ab7213d21546d8f3d93e7 (patch)
treeb15460d7f546f1d6282ff3d5069fd26e4f5c7d39
parenta1652efaebec969dae1f4924744c11e01221de43 (diff)
downloadrspamd-dd2b7b4c24e34d77382ab7213d21546d8f3d93e7.tar.gz
rspamd-dd2b7b4c24e34d77382ab7213d21546d8f3d93e7.zip
[Minor] Add unhex utility
-rw-r--r--lualib/lua_util.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 75d218da3..4b0e50192 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -1473,4 +1473,19 @@ exports.shuffle = function(tbl)
return tbl
end
+--
+local hex_table = {}
+for idx = 0, 255 do
+ hex_table[("%02X"):format(idx)] = string.char(idx)
+ hex_table[("%02x"):format(idx)] = string.char(idx)
+end
+
+---[[[
+-- @function lua_util.unhex(str)
+-- Decode hex encoded string
+-- @param {string} str string to decode
+-- @return {string} hex decoded string (valid hex pairs are decoded, everything else is printed as is)
+--]]]
+exports.unhex = function(str) return str:gsub('(..)', hex_table) end
+
return exports