Software /
code /
prosody
Annotate
util/hashes.lua @ 421:63be85693710
Modules now sending disco replies
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Wed, 26 Nov 2008 08:27:09 +0500 |
parent | 407:7ae008771391 |
rev | line source |
---|---|
148 | 1 |
407
7ae008771391
Fix softreq, so it reports when no suitable MD5 library is found
Matthew Wild <mwild1@gmail.com>
parents:
194
diff
changeset
|
2 local softreq = function (...) local ok, lib = pcall(require, ...); if ok then return lib; else return nil; end end |
155
8c9a9f6f6455
Show error when no MD5 lib available
Matthew Wild <mwild1@gmail.com>
parents:
148
diff
changeset
|
3 local error = error; |
148 | 4 |
5 module "hashes" | |
6 | |
7 local md5 = softreq("md5"); | |
8 if md5 then | |
9 if md5.digest then | |
10 local md5_digest = md5.digest; | |
11 local sha1_digest = sha1.digest; | |
12 function _M.md5(input) | |
13 return md5_digest(input); | |
14 end | |
15 function _M.sha1(input) | |
16 return sha1_digest(input); | |
17 end | |
18 elseif md5.sumhexa then | |
19 local md5_sumhexa = md5.sumhexa; | |
20 function _M.md5(input) | |
21 return md5_sumhexa(input); | |
22 end | |
23 else | |
24 error("md5 library found, but unrecognised... no hash functions will be available", 0); | |
25 end | |
194 | 26 else |
27 error("No md5 library found. Install md5 using luarocks, for example", 0); | |
148 | 28 end |
29 | |
30 return _M; |