1 |
|
2 | (function() {
|
3 | var fn, hash, i, jsSHA, len, ref, sha_type;
|
4 |
|
5 | jsSHA = require("jssha");
|
6 |
|
7 | hash = function(text, algorithm) {
|
8 | var bits, ref, shaObj;
|
9 | if (!algorithm) {
|
10 | throw "No algorithm specified";
|
11 | }
|
12 | bits = (ref = algorithm.match(/^sha-?(\d+)$/i)) != null ? ref[1] : void 0;
|
13 | if (!bits) {
|
14 | throw "Unknown algorithm '" + algorithm + "'";
|
15 | }
|
16 | algorithm = "SHA-" + bits;
|
17 | shaObj = new jsSHA(text, "TEXT");
|
18 | return shaObj.getHash(algorithm, "HEX");
|
19 | };
|
20 |
|
21 | if (module.exports == null) {
|
22 | module.exports = {};
|
23 | }
|
24 |
|
25 | ref = [1, 224, 256, 384, 512];
|
26 | fn = function(sha_type) {
|
27 | var algorithm;
|
28 | algorithm = "sha" + sha_type;
|
29 | return module.exports[algorithm] = function(text) {
|
30 | return hash(text, algorithm);
|
31 | };
|
32 | };
|
33 | for (i = 0, len = ref.length; i < len; i++) {
|
34 | sha_type = ref[i];
|
35 | fn(sha_type);
|
36 | }
|
37 |
|
38 | module.exports.hash = hash;
|
39 |
|
40 | }).call(this);
|