Skip to content

Commit 797455f

Browse files
committed
[Tests] node 17 doesn’t support rmd160
1 parent 33596f6 commit 797455f

File tree

2 files changed

+69
-47
lines changed

2 files changed

+69
-47
lines changed

test/create-hash.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,44 @@
11
'use strict';
22

33
var test = require('tape');
4+
var satisfies = require('semver/functions/satisfies');
45

56
var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'];
67
var encodings = ['hex', 'base64']; // FIXME: test binary
78
var vectors = require('hash-test-vectors');
89

910
function runTest(name, createHash, algorithm) {
10-
test(name + ' test ' + algorithm + ' against test vectors', function (t) {
11-
vectors.forEach(function (obj, i) {
12-
var input = new Buffer(obj.input, 'base64');
13-
var node = obj[algorithm];
14-
var js = createHash(algorithm).update(input).digest('hex');
15-
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node);
11+
var isUnsupported = satisfies(process.version, '^17') && (
12+
algorithm === 'rmd160'
13+
|| algorithm === 'hmac(rmd160)'
14+
);
15+
test(
16+
name + ' test ' + algorithm + ' against test vectors',
17+
{ skip: isUnsupported && 'this node version does not support ' + algorithm },
18+
function (t) {
19+
vectors.forEach(function (obj, i) {
20+
var input = new Buffer(obj.input, 'base64');
21+
var node = obj[algorithm];
22+
var js = createHash(algorithm).update(input).digest('hex');
23+
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node);
1624

17-
encodings.forEach(function (encoding) {
18-
var eInput = new Buffer(obj.input, 'base64').toString(encoding);
19-
var eNode = obj[algorithm];
20-
var eJS = createHash(algorithm).update(eInput, encoding).digest('hex');
21-
t.equal(eJS, eNode, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + eNode);
25+
encodings.forEach(function (encoding) {
26+
var eInput = new Buffer(obj.input, 'base64').toString(encoding);
27+
var eNode = obj[algorithm];
28+
var eJS = createHash(algorithm).update(eInput, encoding).digest('hex');
29+
t.equal(eJS, eNode, algorithm + '(testVector[' + i + '], ' + encoding + ') == ' + eNode);
30+
});
31+
input = new Buffer(obj.input, 'base64');
32+
node = obj[algorithm];
33+
var hash = createHash(algorithm);
34+
hash.end(input);
35+
js = hash.read().toString('hex');
36+
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node);
2237
});
23-
input = new Buffer(obj.input, 'base64');
24-
node = obj[algorithm];
25-
var hash = createHash(algorithm);
26-
hash.end(input);
27-
js = hash.read().toString('hex');
28-
t.equal(js, node, algorithm + '(testVector[' + i + ']) == ' + node);
29-
});
3038

31-
t.end();
32-
});
39+
t.end();
40+
}
41+
);
3342
}
3443

3544
function testLib(name, createHash) {

test/create-hmac.js

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,52 @@
11
'use strict';
22

33
var test = require('tape');
4+
var satisfies = require('semver/functions/satisfies');
45

56
var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'];
67
var vectors = require('hash-test-vectors/hmac');
78

89
function testLib(name, createHmac) {
910
algorithms.forEach(function (alg) {
10-
test(name + ' hmac(' + alg + ')', function (t) {
11-
vectors.forEach(function (input) {
12-
var output = createHmac(alg, new Buffer(input.key, 'hex'))
13-
.update(input.data, 'hex').digest();
14-
15-
output = input.truncate ? output.slice(0, input.truncate) : output;
16-
output = output.toString('hex');
17-
t.equal(output, input[alg]);
18-
});
19-
20-
t.end();
21-
});
22-
23-
test('hmac(' + alg + ')', function (t) {
24-
vectors.forEach(function (input) {
25-
var hmac = createHmac(alg, new Buffer(input.key, 'hex'));
26-
27-
hmac.end(input.data, 'hex');
28-
var output = hmac.read();
29-
30-
output = input.truncate ? output.slice(0, input.truncate) : output;
31-
output = output.toString('hex');
32-
t.equal(output, input[alg]);
33-
});
34-
35-
t.end();
36-
});
11+
var isUnsupported = satisfies(process.version, '^17') && (
12+
alg === 'rmd160'
13+
|| alg === 'hmac(rmd160)'
14+
);
15+
test(
16+
name + ' hmac(' + alg + ')',
17+
{ skip: isUnsupported && 'this node version does not support ' + alg },
18+
function (t) {
19+
vectors.forEach(function (input) {
20+
var output = createHmac(alg, new Buffer(input.key, 'hex'))
21+
.update(input.data, 'hex').digest();
22+
23+
output = input.truncate ? output.slice(0, input.truncate) : output;
24+
output = output.toString('hex');
25+
t.equal(output, input[alg]);
26+
});
27+
28+
t.end();
29+
}
30+
);
31+
32+
test(
33+
'hmac(' + alg + ')',
34+
{ skip: isUnsupported && 'this node version does not support ' + alg },
35+
function (t) {
36+
vectors.forEach(function (input) {
37+
var hmac = createHmac(alg, new Buffer(input.key, 'hex'));
38+
39+
hmac.end(input.data, 'hex');
40+
var output = hmac.read();
41+
42+
output = input.truncate ? output.slice(0, input.truncate) : output;
43+
output = output.toString('hex');
44+
t.equal(output, input[alg]);
45+
});
46+
47+
t.end();
48+
}
49+
);
3750
});
3851
}
3952

0 commit comments

Comments
 (0)