[Pkg-javascript-commits] [node-sha.js] 133/237: fixtures: cleanup of vectors generation
Bastien Roucariès
rouca at moszumanska.debian.org
Fri May 5 09:03:47 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 40f50ccc29db3f689a04ebfecac2753c895398be
Author: Daniel Cousens <github at dcousens.com>
Date: Thu Sep 4 17:36:48 2014 +1000
fixtures: cleanup of vectors generation
---
test/prepare/vectors.js | 80 ++++++++++++++++++++-----------------------------
1 file changed, 33 insertions(+), 47 deletions(-)
diff --git a/test/prepare/vectors.js b/test/prepare/vectors.js
index 11a8321..50c93f0 100644
--- a/test/prepare/vectors.js
+++ b/test/prepare/vectors.js
@@ -1,62 +1,48 @@
-//var tape = require('tape')
-//var Sha1 = require('../')
-var fs = require('fs')
-var path = require('path')
-var to = require('bops/typedarray/to')
-var from = require('bops/typedarray/from')
var assert = require('assert')
var crypto = require('crypto')
+var fs = require('fs')
+var path = require('path')
-//function pad(n, w) {
-// n = n + ''; return new Array(w - n.length + 1).join('0') + n;
-//}
-//
var dir = path.join(__dirname, 'vectors')
-var vectors =
- fs.readdirSync(dir)
- .sort()
- .filter(function (t) {
- return t.match(/\.dat$/);
- })
- .map(function (t) {
- return from(fs.readFileSync(path.join(dir, t), 'base64'), 'base64')
- });
-
-
- var expected = []
- var hashes = {}
-
- ;['sha1', 'sha256', 'md5'].forEach(function (name) {
- hashes[name] =
- fs.readFileSync(path.join(dir, 'byte-hashes.' + name), 'ascii')
- .split(/\r?\n/)
+var vectors = fs.readdirSync(dir)
+ .sort()
+ .filter(function (f) {
+ return f.match(/\.dat$/)
+ })
+ .map(function (f) {
+ return fs.readFileSync(path.join(dir, f))
})
-
+var hashes = {}
+;['sha1', 'sha256', 'md5'].forEach(function (name) {
+ hashes[name] =
+ fs.readFileSync(path.join(dir, 'byte-hashes.' + name), 'ascii')
+ .split(/\r?\n/)
+})
- for (var i = 0; i < vectors.length; i++) {
- expected.push({
- input : to(vectors[i], 'base64'),
- sha1 : hashes.sha1[i],
- sha256 : hashes.sha256[i],
- md4 : hashes.md5[i]
- })
- assert.equal(
- crypto.createHash('sha1').update(new Buffer(vectors[i])).digest('hex'),
- hashes.sha1[i])
+var expected = []
- assert.equal(
- crypto.createHash('sha256').update(new Buffer(vectors[i])).digest('hex'),
- hashes.sha256[i])
+for (var i = 0; i < vectors.length; i++) {
+ expected.push({
+ input : vectors[i].toString('base64'),
+ sha1 : hashes.sha1[i],
+ sha256 : hashes.sha256[i],
+ md4 : hashes.md5[i]
+ })
- assert.equal(
- crypto.createHash('md5').update(new Buffer(vectors[i])).digest('hex'),
- hashes.md5[i])
+ assert.equal(
+ crypto.createHash('sha1').update(new Buffer(vectors[i])).digest('hex'),
+ hashes.sha1[i])
- }
+ assert.equal(
+ crypto.createHash('sha256').update(new Buffer(vectors[i])).digest('hex'),
+ hashes.sha256[i])
-//console.log(expected)
+ assert.equal(
+ crypto.createHash('md5').update(new Buffer(vectors[i])).digest('hex'),
+ hashes.md5[i])
+}
console.log(JSON.stringify(expected, null, 2))
--
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