Mercurial > prosody-hg
comparison util/hashes.lua @ 149:40e443eacbbd
Partial s2s commit
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 24 Oct 2008 07:34:13 +0100 |
| parents | |
| children | 8c9a9f6f6455 |
comparison
equal
deleted
inserted
replaced
| 143:e0f20546cd68 | 149:40e443eacbbd |
|---|---|
| 1 | |
| 2 local softreq = function (...) return select(2, pcall(require, ...)); end | |
| 3 | |
| 4 module "hashes" | |
| 5 | |
| 6 local md5 = softreq("md5"); | |
| 7 if md5 then | |
| 8 if md5.digest then | |
| 9 local md5_digest = md5.digest; | |
| 10 local sha1_digest = sha1.digest; | |
| 11 function _M.md5(input) | |
| 12 return md5_digest(input); | |
| 13 end | |
| 14 function _M.sha1(input) | |
| 15 return sha1_digest(input); | |
| 16 end | |
| 17 elseif md5.sumhexa then | |
| 18 local md5_sumhexa = md5.sumhexa; | |
| 19 function _M.md5(input) | |
| 20 return md5_sumhexa(input); | |
| 21 end | |
| 22 else | |
| 23 error("md5 library found, but unrecognised... no hash functions will be available", 0); | |
| 24 end | |
| 25 end | |
| 26 | |
| 27 return _M; |
