MCPcopy Create free account
hub / github.com/browserify/crypto-browserify / runTest

Function runTest

test/create-hash.js:10–42  ·  view source on GitHub ↗
(name, createHash, algorithm)

Source from the content-addressed store, hash-verified

8var vectors = require('hash-test-vectors');
9
10function 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
44function testLib(name, createHash) {
45 algorithms.forEach(function (algorithm) {

Callers 1

testLibFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…