commit dd2b7b4: [Minor] Add unhex utility
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Dec 21 21:21:04 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-12-21 20:21:06 +0000
URL: https://github.com/rspamd/rspamd/commit/dd2b7b4c24e34d77382ab7213d21546d8f3d93e7
[Minor] Add unhex utility
---
lualib/lua_util.lua | 15 +++++++++++++++
1 file changed, 15 insertions(+)
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
More information about the Commits
mailing list