Sindbad~EG File Manager
--[[
O2switch wrapper/interface for some hashing function
--]]
local _M = {}
local str = require "resty.string"
local tostring = tostring
local type = type
local resty_sha256 = require "resty.sha256"
local sha256 = resty_sha256:new()
local resty_sha1 = require "resty.sha1"
local sha1 = resty_sha1:new()
local md5 = ngx.md5 -- We use the Nginx md5, probably more performant
-- Return a SHA256 hash. Value are cast to string
-- @return data|nil, errorMsg|nil
function _M.sha256(s)
if(type(s) ~= 'string') then
s = tostring(s)
end
sha256:reset()
if sha256:update(s) then
local digest = sha256:final()
return str.to_hex(digest), nil
end
return nil, "sha256: Error, cant retrieve a hash"
end
-- Return a md5 hash. Value are cast to string
-- @return data|nil, errorMsg|nil
function _M.md5(s)
if(type(s) ~= 'string') then
s = tostring(s)
end
return md5(s), nil
end
-- Return a sha1 hash. Value are cast to string
-- @return data|nil, errorMsg|nil
function _M.sha1(s)
if(type(s) ~= 'string') then
s = tostring(s)
end
sha1:reset()
if sha1:update(s) then
local digest = sha1:final()
return str.to_hex(digest), nil
end
return nil, "sha1: Error, cant retrieve a hash"
end
return _M
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists