[Pkg-javascript-commits] [node-sha.js] 18/31: tests: use safe-buffer constructors

Bastien Roucariès rouca at moszumanska.debian.org
Thu Nov 30 11:23:26 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 1ac913b8e043d495c899a1c52258e8e4e970ee95
Author: Daniel Cousens <github at dcousens.com>
Date:   Wed May 24 16:20:15 2017 +1000

    tests: use safe-buffer constructors
---
 test/hash.js    | 15 +++++++--------
 test/test.js    |  6 +++---
 test/vectors.js |  6 ++----
 3 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/test/hash.js b/test/hash.js
index 618b9f1..5fa000d 100644
--- a/test/hash.js
+++ b/test/hash.js
@@ -1,6 +1,5 @@
 var tape = require('tape')
 var Hash = require('../hash')
-
 var hex = '0A1B2C3D4E5F6G7H'
 
 function equal (t, a, b) {
@@ -8,27 +7,27 @@ function equal (t, a, b) {
   t.equal(a.toString('hex'), b.toString('hex'))
 }
 
-var hexBuf = new Buffer('0A1B2C3D4E5F6G7H', 'utf8')
+var hexBuf = Buffer.from('0A1B2C3D4E5F6G7H', 'utf8')
 var count16 = {
   strings: ['0A1B2C3D4E5F6G7H'],
   buffers: [
     hexBuf,
-    new Buffer('80000000000000000000000000000080', 'hex')
+    Buffer.from('80000000000000000000000000000080', 'hex')
   ]
 }
 
 var empty = {
   strings: [''],
   buffers: [
-    new Buffer('80000000000000000000000000000000', 'hex')
+    Buffer.from('80000000000000000000000000000000', 'hex')
   ]
 }
 
 var multi = {
   strings: ['abcd', 'efhijk', 'lmnopq'],
   buffers: [
-    new Buffer('abcdefhijklmnopq', 'ascii'),
-    new Buffer('80000000000000000000000000000080', 'hex')
+    Buffer.from('abcdefhijklmnopq', 'ascii'),
+    Buffer.from('80000000000000000000000000000080', 'hex')
   ]
 }
 
@@ -37,14 +36,14 @@ var long = {
   buffers: [
     hexBuf,
     hexBuf,
-    new Buffer('80000000000000000000000000000100', 'hex')
+    Buffer.from('80000000000000000000000000000100', 'hex')
   ]
 }
 
 function makeTest (name, data) {
   tape(name, function (t) {
     var h = new Hash(16, 8)
-    var hash = new Buffer(20)
+    var hash = Buffer.alloc(20)
     var n = 2
     var expected = data.buffers.slice()
     // t.plan(expected.length + 1)
diff --git a/test/test.js b/test/test.js
index 9f93ee6..623899d 100644
--- a/test/test.js
+++ b/test/test.js
@@ -71,8 +71,8 @@ tape('hex encoding', function (t) {
 
     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')
+      hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex')
+      _hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex')
     }
     var a = hash.digest('hex')
     var e = _hash.digest('hex')
@@ -87,7 +87,7 @@ tape('hex encoding', function (t) {
 tape('call digest for more than MAX_UINT32 bits of data', function (t) {
   var _hash = crypto.createHash('sha1')
   var hash = new Sha1()
-  var bigData = new Buffer(Math.pow(2, 32) / 8)
+  var bigData = Buffer.alloc(Math.pow(2, 32) / 8)
 
   hash.update(bigData)
   _hash.update(bigData)
diff --git a/test/vectors.js b/test/vectors.js
index 622e441..48a646e 100644
--- a/test/vectors.js
+++ b/test/vectors.js
@@ -13,10 +13,10 @@ function makeTest (alg, i, verbose) {
       console.log(v)
       console.log('VECTOR', i)
       console.log('INPUT', v.input)
-      console.log(new Buffer(v.input, 'base64').toString('hex'))
+      console.log(Buffer.from(v.input, 'base64').toString('hex'))
     }
 
-    var buf = new Buffer(v.input, 'base64')
+    var buf = Buffer.from(v.input, 'base64')
     t.equal(createHash(alg).update(buf).digest('hex'), v[alg])
 
     i = ~~(buf.length / 2)
@@ -56,12 +56,10 @@ function makeTest (alg, i, verbose) {
       t.end()
     })
   })
-
 }
 
 if (process.argv[2]) {
   makeTest(process.argv[2], parseInt(process.argv[3], 10), true)
-
 } else {
   vectors.forEach(function (v, i) {
     makeTest('sha', 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