Skip to content

Commit 4e137d4

Browse files
weiyiePeterRao
authored andcommitted
fix: when value is Number,Buffer.alloc replace Buffer.from (#719)
1 parent ae04d43 commit 4e137d4

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"publish-to-cdn": "node publish.js",
3131
"snyk-protect": "snyk protect",
3232
"prepublish": "npm run snyk-protect",
33+
"lint-staged": "lint-staged",
3334
"detect-secrets": "node task/detect-secrets"
3435
},
3536
"git-pre-hooks": {
@@ -38,7 +39,7 @@
3839
"npm run publish-to-npm",
3940
"npm run publish-to-cdn"
4041
],
41-
"pre-commit": "lint-staged"
42+
"pre-commit": "npm run lint-staged"
4243
},
4344
"repository": {
4445
"type": "git",

shims/crypto/crypto.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var algorithms = {
1111
};
1212

1313
var blocksize = 64;
14-
var zeroBuffer = Buffer.from(blocksize);
14+
var zeroBuffer = Buffer.alloc(blocksize);
1515
zeroBuffer.fill(0);
1616

1717
function hmac(fn, key, data) {
@@ -24,7 +24,7 @@ function hmac(fn, key, data) {
2424
key = Buffer.concat([key, zeroBuffer], blocksize)
2525
}
2626

27-
var ipad = Buffer.from(blocksize), opad = Buffer.from(blocksize);
27+
var ipad = Buffer.alloc(blocksize), opad = Buffer.alloc(blocksize);
2828
for(var i = 0; i < blocksize; i++) {
2929
ipad[i] = key[i] ^ 0x36
3030
opad[i] = key[i] ^ 0x5C

shims/crypto/helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var Buffer = require('buffer').Buffer;
22
var intSize = 4;
3-
var zeroBuffer = Buffer.from(intSize); zeroBuffer.fill(0);
3+
var zeroBuffer = Buffer.alloc(intSize); zeroBuffer.fill(0);
44
var chrsz = 8;
55

66
function toArray(buf, bigEndian) {
@@ -18,7 +18,7 @@ function toArray(buf, bigEndian) {
1818
}
1919

2020
function toBuffer(arr, size, bigEndian) {
21-
var buf = Buffer.from(size);
21+
var buf = Buffer.alloc(size);
2222
var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
2323
for (var i = 0; i < arr.length; i++) {
2424
fn.call(buf, arr[i], i * 4, true);

0 commit comments

Comments
 (0)