mirror of
https://github.com/YunoHost/SSOwat.git
synced 2024-09-03 20:06:27 +02:00
Merge pull request #84 from YunoHost/caching_for_hash
[enh] uses caching for hash to avoid heavy recalculation and process spawning
This commit is contained in:
commit
c1a388ccf0
1 changed files with 24 additions and 16 deletions
|
@ -72,6 +72,9 @@ end
|
||||||
|
|
||||||
-- Hash a string using hmac_sha512, return a hexa string
|
-- Hash a string using hmac_sha512, return a hexa string
|
||||||
function hmac_sha512(key, message)
|
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
|
-- lua ecosystem is a disaster and it was not possible to find a good
|
||||||
-- easily multiplatform integrable code for this
|
-- easily multiplatform integrable code for this
|
||||||
-- Python has this buildin, so we call it directly
|
-- 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
|
-- so we need to remove the "(stdin)= " at the beginning
|
||||||
local hash = pipe:read():sub(string.len("(stdin)= ") + 1)
|
local hash = pipe:read():sub(string.len("(stdin)= ") + 1)
|
||||||
pipe:close()
|
pipe:close()
|
||||||
|
|
||||||
|
cache:set(cache_key, hash, conf["session_timeout"])
|
||||||
return hash
|
return hash
|
||||||
|
else
|
||||||
|
return cache:get(cache_key)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue