react / wstein / node_modules / browserify / node_modules / crypto-browserify / node_modules / create-hash / node_modules / sha.js / test / test.js
80559 views1var crypto = require('crypto')2var tape = require('tape')3var Sha1 = require('../').sha14var Uint32toHex = Sha1.Uint32toHex56function generateCount (m) {7var s = ''8for(var i = 0; i < m/8; i++) {9console.log('GENERATE', i, Uint32toHex(i))10s+=i11}12return s13}1415var inputs = [16['', 'ascii'],17['abc', 'ascii'],18['123', 'ascii'],19['123456789abcdef123456789abcdef123456789abcdef123456789abcdef', 'ascii'],20['123456789abcdef123456789abcdef123456789abcdef123456789abc', 'ascii'],21['123456789abcdef123456789abcdef123456789abcdef123456789ab', 'ascii'],22['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde', 'ascii'],23['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', 'ascii'],24['foobarbaz', 'ascii']25]2627tape("hash is the same as node's crypto", function (t) {2829inputs.forEach(function (v) {30var a = new Sha1().update(v[0], v[1]).digest('hex')31var e = crypto.createHash('sha1').update(v[0], v[1]).digest('hex')32console.log(a, '==', e)33t.equal(a, e)34})3536t.end()3738})3940tape('call update multiple times', function (t) {41var n = 142inputs.forEach(function (v) {43var hash = new Sha1()44var _hash = crypto.createHash('sha1')45for(var i = 0; i < v[0].length; i=(i+1)*2) {46var s = v[0].substring(i, (i+1)*2)47hash.update(s, v[1])48_hash.update(s, v[1])49}50var a = hash.digest('hex')51var e = _hash.digest('hex')52console.log(a, '==', e)53t.equal(a, e)54})55t.end()56})575859tape('call update twice', function (t) {6061var _hash = crypto.createHash('sha1')62var hash = new Sha1()6364_hash.update('foo', 'ascii')65hash.update('foo', 'ascii')6667_hash.update('bar', 'ascii')68hash.update('bar', 'ascii')6970_hash.update('baz', 'ascii')71hash.update('baz', 'ascii')7273var a = hash.digest('hex')74var e = _hash.digest('hex')7576t.equal(a, e)77t.end()78})798081tape('hex encoding', function (t) {82var n = 183inputs.forEach(function (v) {84var hash = new Sha1()85var _hash = crypto.createHash('sha1')86for(var i = 0; i < v[0].length; i=(i+1)*2) {87var s = v[0].substring(i, (i+1)*2)88hash.update(new Buffer(s, 'ascii').toString('hex'), 'hex')89_hash.update(new Buffer(s, 'ascii').toString('hex'), 'hex')90}91var a = hash.digest('hex')92var e = _hash.digest('hex')93console.log(a, '==', e)94t.equal(a, e)95})96t.end()97})9899100101