mirror of
https://github.com/YunoHost/SSOwat.git
synced 2024-09-03 20:06:27 +02:00
[enh] uses caching for hash to avoid heavy recalculation and process spawning
This commit is contained in:
parent
37c0980155
commit
76677fab0d
1 changed files with 24 additions and 16 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue