[enh] uses caching for hash to avoid heavy recalculation and process spawning

This commit is contained in:
Laurent Peuch 2017-05-22 23:01:18 +02:00
parent 37c0980155
commit 76677fab0d

View file

@ -72,6 +72,9 @@ end
-- Hash a string using hmac_sha512, return a hexa string
function hmac_sha512(key, message)
local cache_key = key..":"..message
if not cache:get(cache_key) then
-- lua ecosystem is a disaster and it was not possible to find a good
-- easily multiplatform integrable code for this
-- Python has this buildin, so we call it directly
@ -88,7 +91,12 @@ function hmac_sha512(key, message)
-- so we need to remove the "(stdin)= " at the beginning
local hash = pipe:read():sub(string.len("(stdin)= ") + 1)
pipe:close()
cache:set(cache_key, hash, conf["session_timeout"])
return hash
else
return cache:get(cache_key)
end
end