[Pkg-javascript-commits] [node-sha.js] 30/237: tests for hex encoding
Bastien Roucariès
rouca at moszumanska.debian.org
Fri May 5 09:02:52 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-sha.js.
commit f860f65c173ff92b07643ae55a76516de0b1dded
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date: Fri Dec 27 11:37:58 2013 +0700
tests for hex encoding
---
test/hash.js | 2 +-
test/test.js | 34 ++++++++++++++++++++++++++++------
2 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/test/hash.js b/test/hash.js
index fd42c8a..102dec6 100644
--- a/test/hash.js
+++ b/test/hash.js
@@ -78,7 +78,7 @@ function makeTest(name, data) {
}
data.strings.forEach(function (string) {
- h.update(string)
+ h.update(string, 'ascii')
})
t.equal(h.digest(), hash)
diff --git a/test/test.js b/test/test.js
index 00b6af3..25206f5 100644
--- a/test/test.js
+++ b/test/test.js
@@ -3,6 +3,7 @@ var crypto = require('crypto')
var tape = require('tape')
var Sha1 = require('../')
var Uint32toHex = Sha1.Uint32toHex
+var u = require('../util')
function generateCount (m) {
var s = ''
@@ -56,19 +57,20 @@ tape('call update multiple times', function (t) {
t.end()
})
+
tape('call update twice', function (t) {
var _hash = crypto.createHash('sha1')
var hash = new Sha1()
- _hash.update('foo')
- hash.update('foo')
+ _hash.update('foo', 'ascii')
+ hash.update('foo', 'ascii')
- _hash.update('bar')
- hash.update('bar')
+ _hash.update('bar', 'ascii')
+ hash.update('bar', 'ascii')
- _hash.update('baz')
- hash.update('baz')
+ _hash.update('baz', 'ascii')
+ hash.update('baz', 'ascii')
var a = hash.digest('hex')
var e = _hash.digest('hex')
@@ -77,3 +79,23 @@ tape('call update twice', function (t) {
t.end()
})
+
+tape('hex encoding', function (t) {
+ var n = 1
+ 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(u.toHex(s), 'hex')
+ _hash.update(u.toHex(s), 'hex')
+ }
+ var a = hash.digest('hex')
+ var e = _hash.digest('hex')
+ console.log(a, '==', e)
+ t.equal(a, e)
+ })
+ t.end()
+})
+
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-sha.js.git
More information about the Pkg-javascript-commits
mailing list