# signature { license=0, seed=457995617, key="15d3efdcc3cc2f150e0e11b4b501e478" }
local md5 = require("md5")
local exor,rep = md5.exor, string.rep

local function _hmac(key, text, hash, hex)
	assert(type(key)  == 'string', "key must be a string")
	assert(type(text) == 'string', "text must be a string")
	hash = hash or md5
	if #key > hash.BLOCK_SIZE then key = hash(key) end
	key = key .. rep("\0", hash.BLOCK_SIZE - #key)
	return hash(exor(key,"\x5c") .. hash(exor(key,"\x36") .. text), hex)
end

local hmac = {
	_VERSION = "hmac 1.0.2";
	hmac     = _hmac;
}

setmetatable( hmac, {__call = function(_,key, text, hash, hex) return _hmac(key, text, hash, hex) end })

return hmac

