File

util/hashes.lua @ 190:1e993b7deae7

General fixes for s2s, to make it more robust (I hope), sending data to remote hosts sane (s2ssession.send() works as expected), recycle outgoing dialback connections, etc.
author Matthew Wild <mwild1@gmail.com>
date Sat, 01 Nov 2008 18:28:46 +0000
parent 155:8c9a9f6f6455
child 194:4ea1ec218976
line wrap: on
line source


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
end

return _M;