|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 | 3 | var test = require('tape');
|
| 4 | +var satisfies = require('semver/functions/satisfies'); |
4 | 5 |
|
5 | 6 | var algorithms = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'];
|
6 | 7 | var encodings = ['hex', 'base64']; // FIXME: test binary
|
7 | 8 | var vectors = require('hash-test-vectors');
|
8 | 9 |
|
9 | 10 | 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); |
16 | 24 |
|
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); |
22 | 37 | });
|
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 |
| - }); |
30 | 38 |
|
31 |
| - t.end(); |
32 |
| - }); |
| 39 | + t.end(); |
| 40 | + } |
| 41 | + ); |
33 | 42 | }
|
34 | 43 |
|
35 | 44 | function testLib(name, createHash) {
|
|
0 commit comments