-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.js
43 lines (39 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
const HighwayHash = require('./build/Release/highwayhash.node');
const assertKey = function (key) {
if (!(Buffer.isBuffer(key) && key.length === 32)) {
throw new Error('Expected key to be a 32 byte Buffer: ' + key);
}
};
const assertInput = function (input) {
if (!Buffer.isBuffer(input)) {
throw new Error('Expected input to be a Buffer: ' + input);
}
};
module.exports = {
asBuffer: function (key, input) {
assertKey(key);
assertInput(input);
return HighwayHash.AsBuffer(key, input);
},
asString: function (key, input) {
assertKey(key);
assertInput(input);
return HighwayHash.AsString(key, input);
},
asHexString: function (key, input) {
assertKey(key);
assertInput(input);
return HighwayHash.AsHexString(key, input);
},
asUInt32Low: function (key, input) {
assertKey(key);
assertInput(input);
return HighwayHash.AsUInt32Low(key, input);
},
asUInt32High: function (key, input) {
assertKey(key);
assertInput(input);
return HighwayHash.AsUInt32High(key, input);
}
};