diff --git a/functions.lua b/functions.lua index 7572dc5..576caed 100644 --- a/functions.lua +++ b/functions.lua @@ -16,10 +16,8 @@ end -- https://en.wikipedia.org/wiki/HMAC local i_pad = "" local o_pad = "" -for _=1,64 do - i_pad = i_pad .. string.char(0x36) - o_pad = o_pad .. string.char(0x5c) -end +i_pad = string.char(0x36):rep(64) +o_pad = string.char(0x5c):rep(64) -- hmac generation function fediauth.hmac(key, message) @@ -60,10 +58,7 @@ function fediauth.hmac(key, message) end local function left_pad(str, s, len) - while #str < len do - str = s .. str - end - return str + return s:rep(#str - len) .. str end function fediauth.generate_tfediauth(secret_b32, unix_time) @@ -125,10 +120,7 @@ end function fediauth.generate_secret() local buf = minetest.sha1("" .. math.random(10000), true) - local s = "" - for i=1,20 do - s = s .. string.char(string.byte(buf, i)) - end + local s = buf:sub(1, 20) return s end