aboutsummaryrefslogtreecommitdiff
path: root/node_modules/sha.js/test/test.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
commitde98e0b232509d5f40c135d540a70e415272ff85 (patch)
treea79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/sha.js/test/test.js
parente0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff)
node_modules
Diffstat (limited to 'node_modules/sha.js/test/test.js')
-rw-r--r--node_modules/sha.js/test/test.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/node_modules/sha.js/test/test.js b/node_modules/sha.js/test/test.js
new file mode 100644
index 000000000..0a46e44be
--- /dev/null
+++ b/node_modules/sha.js/test/test.js
@@ -0,0 +1,85 @@
+var crypto = require('crypto')
+var tape = require('tape')
+var Sha1 = require('../').sha1
+
+var inputs = [
+ ['', 'ascii'],
+ ['abc', 'ascii'],
+ ['123', 'ascii'],
+ ['123456789abcdef123456789abcdef123456789abcdef123456789abcdef', 'ascii'],
+ ['123456789abcdef123456789abcdef123456789abcdef123456789abc', 'ascii'],
+ ['123456789abcdef123456789abcdef123456789abcdef123456789ab', 'ascii'],
+ ['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde', 'ascii'],
+ ['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', 'ascii'],
+ ['foobarbaz', 'ascii']
+]
+
+tape("hash is the same as node's crypto", function (t) {
+ inputs.forEach(function (v) {
+ var a = new Sha1().update(v[0], v[1]).digest('hex')
+ var e = crypto.createHash('sha1').update(v[0], v[1]).digest('hex')
+ console.log(a, '==', e)
+ t.equal(a, e)
+ })
+
+ t.end()
+})
+
+tape('call update multiple times', function (t) {
+ inputs.forEach(function (v) {
+ var hash = new Sha1()
+ var _hash = crypto.createHash('sha1')
+
+ for (var i = 0; i < v[0].length; i = (i + 1) * 2) {
+ var s = v[0].substring(i, (i + 1) * 2)
+ hash.update(s, v[1])
+ _hash.update(s, v[1])
+ }
+
+ var a = hash.digest('hex')
+ var e = _hash.digest('hex')
+ console.log(a, '==', e)
+ t.equal(a, e)
+ })
+ t.end()
+})
+
+tape('call update twice', function (t) {
+ var _hash = crypto.createHash('sha1')
+ var hash = new Sha1()
+
+ _hash.update('foo', 'ascii')
+ hash.update('foo', 'ascii')
+
+ _hash.update('bar', 'ascii')
+ hash.update('bar', 'ascii')
+
+ _hash.update('baz', 'ascii')
+ hash.update('baz', 'ascii')
+
+ var a = hash.digest('hex')
+ var e = _hash.digest('hex')
+
+ t.equal(a, e)
+ t.end()
+})
+
+tape('hex encoding', function (t) {
+ inputs.forEach(function (v) {
+ var hash = new Sha1()
+ var _hash = crypto.createHash('sha1')
+
+ 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')
+ }
+ var a = hash.digest('hex')
+ var e = _hash.digest('hex')
+
+ console.log(a, '==', e)
+ t.equal(a, e)
+ })
+
+ t.end()
+})