Skip to content

Commit

Permalink
test: test that all algos match Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed May 31, 2020
1 parent 55e9196 commit c52c81b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var crypto = require('crypto')
var tape = require('tape')
var Sha1 = require('../').sha1
var sha = require('../')

var inputs = [
['', 'ascii'],
Expand All @@ -25,6 +26,21 @@ tape("hash is the same as node's crypto", function (t) {
t.end()
})

tape("hash is the same as node's crypto for all algos provided by node", function (t) {
var hashes = crypto.getHashes()
Object.keys(sha).forEach(function (alg) {
if (hashes.indexOf(alg) === -1) return // skip unsupported by current Node.js version
inputs.forEach(function (v) {
var a = new sha[alg]().update(v[0], v[1]).digest('hex')
var e = crypto.createHash(alg).update(v[0], v[1]).digest('hex')
console.log(alg, a, '==', e)
t.equal(a, e)
})
})

t.end()
})

tape('call update multiple times', function (t) {
inputs.forEach(function (v) {
var hash = new Sha1()
Expand Down

0 comments on commit c52c81b

Please sign in to comment.