[Pkg-javascript-commits] [node-sha.js] 52/237: update vector test to cover sha256
Bastien Roucariès
rouca at moszumanska.debian.org
Fri May 5 09:02:54 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 aa0d4faef9f05aedf388bf9ca0e5012c4fc14326
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date: Fri Dec 27 21:08:01 2013 +0700
update vector test to cover sha256
---
test/vectors.js | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/test/vectors.js b/test/vectors.js
index a74962b..364b60c 100644
--- a/test/vectors.js
+++ b/test/vectors.js
@@ -1,31 +1,45 @@
var vectors = require('./nist-vectors.json')
-var Sha1 = require('../')
var tape = require('tape')
var from = require('bops/typedarray/from')
var hexpp = require('../hexpp')
-function makeTest(i, verbose) {
+var Sha1 = require('../')
+var Sha256 = require('../sha256')
+
+function createHash(alg) {
+ return (
+ 'sha1' == alg ? new Sha1()
+ : 'sha256' == alg ? new Sha256()
+ : (function () { throw new Error(alg + ' is not supported') }) ()
+ )
+}
+
+function makeTest(alg, i, verbose) {
var v = vectors[i]
- tape('NIST vector ' + i, function (t) {
+
+ tape(alg + ': NIST vector ' + i, function (t) {
if(verbose) {
+ console.log(v)
console.log('VECTOR', i)
console.log('INPUT', v.input)
console.log(hexpp(from(v.input, 'base64')))
console.log(new Buffer(v.input, 'base64').toString('hex'))
}
var buf = from(v.input, 'base64')
- t.equal(new Sha1().update(buf).digest('hex'), v.sha1)
+// console.log(createHash(alg).update(buf))
+ t.equal(createHash(alg).update(buf).digest('hex'), v[alg])
t.end()
})
}
if(process.argv[2])
- makeTest(parseInt(process.argv[2]), true)
+ makeTest(process.argv[2], parseInt(process.argv[3]), true)
else
vectors.forEach(function (v, i) {
- makeTest(i)
+ makeTest('sha1', i)
+ makeTest('sha256', i)
})
--
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