mod_s2s: Remove warning about hostname mismatch
[prosody.git] / util / hex.lua
blob4cc28d33386f1f42dbe7d7cd1216e37757943e6c
1 local s_char = string.char;
2 local s_format = string.format;
3 local s_gsub = string.gsub;
4 local s_lower = string.lower;
6 local char_to_hex = {};
7 local hex_to_char = {};
9 do
10 local char, hex;
11 for i = 0,255 do
12 char, hex = s_char(i), s_format("%02x", i);
13 char_to_hex[char] = hex;
14 hex_to_char[hex] = char;
15 end
16 end
18 local function to(s)
19 return (s_gsub(s, ".", char_to_hex));
20 end
22 local function from(s)
23 return (s_gsub(s_lower(s), "%X*(%x%x)%X*", hex_to_char));
24 end
26 return { to = to, from = from }