[Pkg-javascript-commits] [node-sha.js] 104/237: remove custom encoding stuff - just use buffer
Bastien Roucariès
rouca at moszumanska.debian.org
Fri May 5 09:03:44 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 b464d5bf5cd34de2cb294108179e6967bf3aef28
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date: Wed Jan 15 16:20:13 2014 +0700
remove custom encoding stuff - just use buffer
---
test/enc.js | 57 ---------------------------------------------------------
test/test.js | 4 ++--
test/vectors.js | 1 -
test/write.js | 14 +++++++-------
4 files changed, 9 insertions(+), 67 deletions(-)
diff --git a/test/enc.js b/test/enc.js
deleted file mode 100644
index 00f39b0..0000000
--- a/test/enc.js
+++ /dev/null
@@ -1,57 +0,0 @@
-
-var Sha1 = require('../').sha1
-var tape = require('tape')
-var toString = require('../util').toString
-var Buffer = require('native-buffer-browserify').Buffer
-var toBuffer = function (b, e) {
- return new Buffer(b, e)
-}
-
-var EMPTY = new Uint8Array([
- 218, 57, 163, 238, 94, 107, 75, 13,
- 50, 85, 191, 239, 149, 96, 24, 144,
- 175, 216, 7, 9
- ])
-
-function equalBuffers(a, b, t) {
-
- if(a.length !== b.length) throw new Error('different lengths')
- for(var i = 0; i < a.length; i++)
- if(a[i] !== b[i])
- t.fail('buffers differ at index:' + i + '(' + a[i] + ' != ' + b[i] + ')')
-}
-
-
-tape('all the output encodings work', function (t) {
- var hex = new Sha1().update('', 'ascii').digest('hex')
- var buffer = new Sha1().update('', 'ascii').digest()
- var base64 = new Sha1().update('', 'ascii').digest('base64')
-
- t.equal(base64, '2jmj7l5rSw0yVb/vlWAYkK/YBwk=')
- t.equal(hex, 'da39a3ee5e6b4b0d3255bfef95601890afd80709')
-
- t.notEqual(typeof buffer, 'string')
- console.error('output', typeof buffer)
- equalBuffers(buffer, EMPTY, t)
-
- t.end()
-})
-
-tape('base64', function (t) {
- equalBuffers(toBuffer(toString(EMPTY, 'base64'), 'base64'), EMPTY, t)
- t.end()
-})
-
-tape('all input encodings work2', function (t) {
- var hex = new Sha1().update(toString(EMPTY, 'hex'), 'hex').digest('hex')
- var base64 = new Sha1().update(toString(EMPTY, 'base64'), 'base64').digest('hex')
- console.log('Binary:', JSON.stringify(toString(EMPTY, 'binary')))
- var binary = new Sha1().update(toString(EMPTY, 'binary'), 'binary').digest('hex')
- var buffer = new Sha1().update(EMPTY).digest('hex')
- console.log(hex, base64, buffer)
- equalBuffers(hex, base64, t)
- equalBuffers(hex, buffer, t)
- equalBuffers(hex, binary, t)
- t.end()
-})
-
diff --git a/test/test.js b/test/test.js
index 4f3b1dd..66c089d 100644
--- a/test/test.js
+++ b/test/test.js
@@ -87,8 +87,8 @@ tape('hex encoding', function (t) {
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')
+ 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')
diff --git a/test/vectors.js b/test/vectors.js
index afa7117..6fbd428 100644
--- a/test/vectors.js
+++ b/test/vectors.js
@@ -19,7 +19,6 @@ function makeTest(alg, i, verbose) {
console.log(new Buffer(v.input, 'base64').toString('hex'))
}
var buf = new Buffer(v.input, 'base64')
-// console.log(createHash(alg).update(buf))
t.equal(createHash(alg).update(buf).digest('hex'), v[alg])
t.end()
})
diff --git a/test/write.js b/test/write.js
index 0285ea8..4f8146a 100644
--- a/test/write.js
+++ b/test/write.js
@@ -2,7 +2,6 @@ var tape = require('tape')
var write = require('../util').write
var hexpp = require('../hexpp')
var u = require('../util')
-var to = require('bops/typedarray/to')
function toBuffer (string) {
var a = new Uint8Array(string.length)
@@ -30,12 +29,13 @@ var FOO = toBuffer('foo')
var BAR = toBuffer('bar')
var BAZ = toBuffer('baz')
-var FOO64 = to(FOO, 'base64')
-var BAR64 = to(BAR, 'base64')
-var BAZ64 = to(BAZ, 'base64')
-var FOOx = u.toHex('foo')
-var BARx = u.toHex('bar')
-var BAZx = u.toHex('baz')
+var FOO64 = FOO.toString('base64')
+var BAR64 = BAR.toString('base64')
+var BAZ64 = BAZ.toString('base64')
+
+var FOOx = FOO.toString('hex')
+var BARx = BAR.toString('hex')
+var BAZx = BAZ.toString('hex')
tape('hello there, ascii', function (t) {
var expected = HELLOTHERE
--
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