Skip to content

Commit 100edf9

Browse files
committed
Buffer: use alloc/allocUnsafe/from instead new
1 parent 271e39b commit 100edf9

File tree

7 files changed

+8
-8
lines changed

7 files changed

+8
-8
lines changed

hash.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var Buffer = require('safe-buffer').Buffer
22

33
// prototype class for hash functions
44
function Hash (blockSize, finalSize) {
5-
this._block = new Buffer(blockSize)
5+
this._block = Buffer.alloc(blockSize)
66
this._finalSize = finalSize
77
this._blockSize = blockSize
88
this._len = 0
@@ -11,7 +11,7 @@ function Hash (blockSize, finalSize) {
1111
Hash.prototype.update = function (data, enc) {
1212
if (typeof data === 'string') {
1313
enc = enc || 'utf8'
14-
data = new Buffer(data, enc)
14+
data = Buffer.from(data, enc)
1515
}
1616

1717
var block = this._block

sha.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Sha.prototype._update = function (M) {
8080
}
8181

8282
Sha.prototype._hash = function () {
83-
var H = new Buffer(20)
83+
var H = Buffer.allocUnsafe(20)
8484

8585
H.writeInt32BE(this._a | 0, 0)
8686
H.writeInt32BE(this._b | 0, 4)

sha1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Sha1.prototype._update = function (M) {
8585
}
8686

8787
Sha1.prototype._hash = function () {
88-
var H = new Buffer(20)
88+
var H = Buffer.allocUnsafe(20)
8989

9090
H.writeInt32BE(this._a | 0, 0)
9191
H.writeInt32BE(this._b | 0, 4)

sha224.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Sha224.prototype.init = function () {
3737
}
3838

3939
Sha224.prototype._hash = function () {
40-
var H = new Buffer(28)
40+
var H = Buffer.allocUnsafe(28)
4141

4242
H.writeInt32BE(this._a, 0)
4343
H.writeInt32BE(this._b, 4)

sha256.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Sha256.prototype._update = function (M) {
118118
}
119119

120120
Sha256.prototype._hash = function () {
121-
var H = new Buffer(32)
121+
var H = Buffer.allocUnsafe(32)
122122

123123
H.writeInt32BE(this._a, 0)
124124
H.writeInt32BE(this._b, 4)

sha384.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Sha384.prototype.init = function () {
3737
}
3838

3939
Sha384.prototype._hash = function () {
40-
var H = new Buffer(48)
40+
var H = Buffer.allocUnsafe(48)
4141

4242
function writeInt64BE (h, l, offset) {
4343
H.writeInt32BE(h, offset)

sha512.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ Sha512.prototype._update = function (M) {
238238
}
239239

240240
Sha512.prototype._hash = function () {
241-
var H = new Buffer(64)
241+
var H = Buffer.allocUnsafe(64)
242242

243243
function writeInt64BE (h, l, offset) {
244244
H.writeInt32BE(h, offset)

0 commit comments

Comments
 (0)