annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
149
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local softreq = function (...) return select(2, pcall(require, ...)); end
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 module "hashes"
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local md5 = softreq("md5");
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 if md5 then
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 if md5.digest then
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local md5_digest = md5.digest;
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local sha1_digest = sha1.digest;
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 function _M.md5(input)
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 return md5_digest(input);
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 end
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 function _M.sha1(input)
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 return sha1_digest(input);
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 end
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 elseif md5.sumhexa then
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 local md5_sumhexa = md5.sumhexa;
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 function _M.md5(input)
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 return md5_sumhexa(input);
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 end
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 else
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 error("md5 library found, but unrecognised... no hash functions will be available", 0);
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 end
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 end
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
40e443eacbbd Partial s2s commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 return _M;