Skip to content

Commit 1ac913b

Browse files
committed
tests: use safe-buffer constructors
1 parent 8551e53 commit 1ac913b

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

test/hash.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
var tape = require('tape')
22
var Hash = require('../hash')
3-
43
var hex = '0A1B2C3D4E5F6G7H'
54

65
function equal (t, a, b) {
76
t.equal(a.length, b.length)
87
t.equal(a.toString('hex'), b.toString('hex'))
98
}
109

11-
var hexBuf = new Buffer('0A1B2C3D4E5F6G7H', 'utf8')
10+
var hexBuf = Buffer.from('0A1B2C3D4E5F6G7H', 'utf8')
1211
var count16 = {
1312
strings: ['0A1B2C3D4E5F6G7H'],
1413
buffers: [
1514
hexBuf,
16-
new Buffer('80000000000000000000000000000080', 'hex')
15+
Buffer.from('80000000000000000000000000000080', 'hex')
1716
]
1817
}
1918

2019
var empty = {
2120
strings: [''],
2221
buffers: [
23-
new Buffer('80000000000000000000000000000000', 'hex')
22+
Buffer.from('80000000000000000000000000000000', 'hex')
2423
]
2524
}
2625

2726
var multi = {
2827
strings: ['abcd', 'efhijk', 'lmnopq'],
2928
buffers: [
30-
new Buffer('abcdefhijklmnopq', 'ascii'),
31-
new Buffer('80000000000000000000000000000080', 'hex')
29+
Buffer.from('abcdefhijklmnopq', 'ascii'),
30+
Buffer.from('80000000000000000000000000000080', 'hex')
3231
]
3332
}
3433

@@ -37,14 +36,14 @@ var long = {
3736
buffers: [
3837
hexBuf,
3938
hexBuf,
40-
new Buffer('80000000000000000000000000000100', 'hex')
39+
Buffer.from('80000000000000000000000000000100', 'hex')
4140
]
4241
}
4342

4443
function makeTest (name, data) {
4544
tape(name, function (t) {
4645
var h = new Hash(16, 8)
47-
var hash = new Buffer(20)
46+
var hash = Buffer.alloc(20)
4847
var n = 2
4948
var expected = data.buffers.slice()
5049
// t.plan(expected.length + 1)

test/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ tape('hex encoding', function (t) {
7171

7272
for (var i = 0; i < v[0].length; i = (i + 1) * 2) {
7373
var s = v[0].substring(i, (i + 1) * 2)
74-
hash.update(new Buffer(s, 'ascii').toString('hex'), 'hex')
75-
_hash.update(new Buffer(s, 'ascii').toString('hex'), 'hex')
74+
hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex')
75+
_hash.update(Buffer.from(s, 'ascii').toString('hex'), 'hex')
7676
}
7777
var a = hash.digest('hex')
7878
var e = _hash.digest('hex')
@@ -87,7 +87,7 @@ tape('hex encoding', function (t) {
8787
tape('call digest for more than MAX_UINT32 bits of data', function (t) {
8888
var _hash = crypto.createHash('sha1')
8989
var hash = new Sha1()
90-
var bigData = new Buffer(Math.pow(2, 32) / 8)
90+
var bigData = Buffer.alloc(Math.pow(2, 32) / 8)
9191

9292
hash.update(bigData)
9393
_hash.update(bigData)

test/vectors.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ function makeTest (alg, i, verbose) {
1313
console.log(v)
1414
console.log('VECTOR', i)
1515
console.log('INPUT', v.input)
16-
console.log(new Buffer(v.input, 'base64').toString('hex'))
16+
console.log(Buffer.from(v.input, 'base64').toString('hex'))
1717
}
1818

19-
var buf = new Buffer(v.input, 'base64')
19+
var buf = Buffer.from(v.input, 'base64')
2020
t.equal(createHash(alg).update(buf).digest('hex'), v[alg])
2121

2222
i = ~~(buf.length / 2)
@@ -56,12 +56,10 @@ function makeTest (alg, i, verbose) {
5656
t.end()
5757
})
5858
})
59-
6059
}
6160

6261
if (process.argv[2]) {
6362
makeTest(process.argv[2], parseInt(process.argv[3], 10), true)
64-
6563
} else {
6664
vectors.forEach(function (v, i) {
6765
makeTest('sha', i)

0 commit comments

Comments
 (0)