Skip to content

Commit 8048a63

Browse files
committed
test: test that all algos match Node.js
1 parent 105bfe5 commit 8048a63

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var crypto = require('crypto')
22
var tape = require('tape')
33
var Sha1 = require('../').sha1
4+
var sha = require('../')
45

56
var inputs = [
67
['', 'ascii'],
@@ -25,6 +26,20 @@ tape("hash is the same as node's crypto", function (t) {
2526
t.end()
2627
})
2728

29+
tape("hash is the same as node's crypto for all algos provided by node", function (t) {
30+
Object.keys(sha).forEach(function (alg) {
31+
if (alg === 'sha') return
32+
inputs.forEach(function (v) {
33+
var a = new sha[alg]().update(v[0], v[1]).digest('hex')
34+
var e = crypto.createHash(alg).update(v[0], v[1]).digest('hex')
35+
console.log(alg, a, '==', e)
36+
t.equal(a, e)
37+
})
38+
})
39+
40+
t.end()
41+
})
42+
2843
tape('call update multiple times', function (t) {
2944
inputs.forEach(function (v) {
3045
var hash = new Sha1()

0 commit comments

Comments
 (0)