(name, createHash, algorithm)
| 8 | var vectors = require('hash-test-vectors'); |
| 9 | |
| 10 | function runTest(name, createHash, algorithm) { |
| 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); |
| 24 | |
| 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); |
| 37 | }); |
| 38 | |
| 39 | t.end(); |
| 40 | } |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | function testLib(name, createHash) { |
| 45 | algorithms.forEach(function (algorithm) { |
no outgoing calls
no test coverage detected
searching dependent graphs…