Annotate

util/hashes.lua @ 5558:774ab5f2efa6 s2s

Close 's2s' branch
author Matthew Wild <mwild1@gmail.com>
date Wed, 01 May 2013 13:54:00 +0100
parent 148:4c0dcd245d34
child 155:8c9a9f6f6455
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
148
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local softreq = function (...) return select(2, pcall(require, ...)); end
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 module "hashes"
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local md5 = softreq("md5");
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 if md5 then
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 if md5.digest then
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local md5_digest = md5.digest;
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local sha1_digest = sha1.digest;
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 function _M.md5(input)
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 return md5_digest(input);
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 end
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 function _M.sha1(input)
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 return sha1_digest(input);
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 end
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 elseif md5.sumhexa then
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 local md5_sumhexa = md5.sumhexa;
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 function _M.md5(input)
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 return md5_sumhexa(input);
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 end
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 else
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 error("md5 library found, but unrecognised... no hash functions will be available", 0);
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 end
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 end
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
4c0dcd245d34 s2s works! \o/ \o/
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 return _M;