util/hashes.lua

Fri, 21 Nov 2008 05:59:03 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 21 Nov 2008 05:59:03 +0000
changeset 372
e7c1e30d06d5
parent 194
4ea1ec218976
child 407
7ae008771391
permissions
-rw-r--r--

Now possible to specify nil origin to core_route_stanza. Origin will be chosen as the host of the 'from' attribute on the stanza. Returns false on no such host.


local softreq = function (...) return select(2, pcall(require, ...)); end
local error = error;

module "hashes"

local md5 = softreq("md5");
if md5 then
	if md5.digest then
		local md5_digest = md5.digest;
		local sha1_digest = sha1.digest;
		function _M.md5(input)
			return md5_digest(input);
		end
		function _M.sha1(input)
			return sha1_digest(input);
		end
	elseif md5.sumhexa then
		local md5_sumhexa = md5.sumhexa;
		function _M.md5(input)
			return md5_sumhexa(input);
		end
	else
		error("md5 library found, but unrecognised... no hash functions will be available", 0);
	end
else
	error("No md5 library found. Install md5 using luarocks, for example", 0);
end

return _M;

mercurial