diff options
Diffstat (limited to 'node_modules/sha.js/test')
-rw-r--r-- | node_modules/sha.js/test/hash.js | 39 | ||||
-rw-r--r-- | node_modules/sha.js/test/test.js | 19 | ||||
-rw-r--r-- | node_modules/sha.js/test/vectors.js | 10 |
3 files changed, 34 insertions, 34 deletions
diff --git a/node_modules/sha.js/test/hash.js b/node_modules/sha.js/test/hash.js index 2f376b4d9..5fa000d5a 100644 --- a/node_modules/sha.js/test/hash.js +++ b/node_modules/sha.js/test/hash.js @@ -1,73 +1,62 @@ -var hexpp = require('../hexpp').defaults({ bigendian: false }) var tape = require('tape') var Hash = require('../hash') - var hex = '0A1B2C3D4E5F6G7H' function equal (t, a, b) { t.equal(a.length, b.length) - - for (var i = 0; i < a.length; i++) { - t.equal(a[i], b[i]) - } + t.equal(a.toString('hex'), b.toString('hex')) } -var hexBuf = new Buffer([48, 65, 49, 66, 50, 67, 51, 68, 52, 69, 53, 70, 54, 71, 55, 72]) +var hexBuf = Buffer.from('0A1B2C3D4E5F6G7H', 'utf8') var count16 = { strings: ['0A1B2C3D4E5F6G7H'], buffers: [ hexBuf, - new Buffer([ 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128]) + Buffer.from('80000000000000000000000000000080', 'hex') ] } var empty = { strings: [''], buffers: [ - new Buffer([ 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]) + Buffer.from('80000000000000000000000000000000', 'hex') ] } var multi = { - strings: ['abcd', 'efhijk', 'lmnopq'], - buffers: [ - new Buffer('abcdefhijklmnopq', 'ascii'), - new Buffer([128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128]) - ] - } + strings: ['abcd', 'efhijk', 'lmnopq'], + buffers: [ + Buffer.from('abcdefhijklmnopq', 'ascii'), + Buffer.from('80000000000000000000000000000080', 'hex') + ] +} var long = { strings: [hex + hex], buffers: [ hexBuf, hexBuf, - new Buffer([128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]) + Buffer.from('80000000000000000000000000000100', 'hex') ] } function makeTest (name, data) { tape(name, function (t) { - var h = new Hash(16, 8) - var hash = new Buffer(20) + var hash = Buffer.alloc(20) var n = 2 var expected = data.buffers.slice() // t.plan(expected.length + 1) h._update = function (block) { var e = expected.shift() - - console.log('---block---') - console.log(hexpp(block), block.length) - console.log('---e---') - console.log(hexpp(e), block.length) - console.log(block) equal(t, block, e) if (n < 0) { throw new Error('expecting only 2 calls to _update') } - + } + h._hash = function () { return hash } diff --git a/node_modules/sha.js/test/test.js b/node_modules/sha.js/test/test.js index 0a46e44be..623899ddb 100644 --- a/node_modules/sha.js/test/test.js +++ b/node_modules/sha.js/test/test.js @@ -71,8 +71,8 @@ tape('hex encoding', function (t) { for (var i = 0; i < v[0].length; i = (i + 1) * 2) { var s = v[0].substring(i, (i + 1) * 2) - hash.update(new Buffer(s, 'ascii').toString('hex'), 'hex') - _hash.update(new Buffer(s, 'ascii').toString('hex'), 'hex') + hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex') + _hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex') } var a = hash.digest('hex') var e = _hash.digest('hex') @@ -83,3 +83,18 @@ tape('hex encoding', function (t) { t.end() }) + +tape('call digest for more than MAX_UINT32 bits of data', function (t) { + var _hash = crypto.createHash('sha1') + var hash = new Sha1() + var bigData = Buffer.alloc(Math.pow(2, 32) / 8) + + hash.update(bigData) + _hash.update(bigData) + + var a = hash.digest('hex') + var e = _hash.digest('hex') + + t.equal(a, e) + t.end() +}) diff --git a/node_modules/sha.js/test/vectors.js b/node_modules/sha.js/test/vectors.js index 4aef39cc3..48a646ef6 100644 --- a/node_modules/sha.js/test/vectors.js +++ b/node_modules/sha.js/test/vectors.js @@ -1,8 +1,7 @@ var tape = require('tape') var vectors = require('hash-test-vectors') // var from = require('bops/typedarray/from') -var Buffer = require('buffer').Buffer -var hexpp = require('../hexpp') +var Buffer = require('safe-buffer').Buffer var createHash = require('../') @@ -14,11 +13,10 @@ function makeTest (alg, i, verbose) { console.log(v) console.log('VECTOR', i) console.log('INPUT', v.input) - console.log(hexpp(new Buffer(v.input, 'base64'))) - console.log(new Buffer(v.input, 'base64').toString('hex')) + console.log(Buffer.from(v.input, 'base64').toString('hex')) } - var buf = new Buffer(v.input, 'base64') + var buf = Buffer.from(v.input, 'base64') t.equal(createHash(alg).update(buf).digest('hex'), v[alg]) i = ~~(buf.length / 2) @@ -58,12 +56,10 @@ function makeTest (alg, i, verbose) { t.end() }) }) - } if (process.argv[2]) { makeTest(process.argv[2], parseInt(process.argv[3], 10), true) - } else { vectors.forEach(function (v, i) { makeTest('sha', i) |