Replace new Buffer() with Buffer.alloc() in lib/crypto - do it everywhere!

This commit is contained in:
Lee Miller 2023-01-03 06:17:21 +02:00
parent c10e2830f5
commit 573ed263bc
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63

View File

@ -104,15 +104,15 @@ var encrypted = exports.encrypted = {
assert(buf.readUInt16BE(16, true) === SECP256K1_TYPE, "Bad curve type"); assert(buf.readUInt16BE(16, true) === SECP256K1_TYPE, "Bad curve type");
assert(buf.readUInt16BE(18, true) === 32, "Bad Rx length"); assert(buf.readUInt16BE(18, true) === 32, "Bad Rx length");
assert(buf.readUInt16BE(52, true) === 32, "Bad Ry length"); assert(buf.readUInt16BE(52, true) === 32, "Bad Ry length");
var iv = new Buffer(16); var iv = Buffer.alloc(16);
buf.copy(iv, 0, 0, 16); buf.copy(iv, 0, 0, 16);
var ephemPublicKey = new Buffer(70); var ephemPublicKey = Buffer.alloc(70);
buf.copy(ephemPublicKey, 0, 16, 86); buf.copy(ephemPublicKey, 0, 16, 86);
// NOTE(Kagami): We do copy instead of slice to protect against // NOTE(Kagami): We do copy instead of slice to protect against
// possible source buffer modification by user. // possible source buffer modification by user.
var ciphertext = new Buffer(buf.length - 118); var ciphertext = Buffer.alloc(buf.length - 118);
buf.copy(ciphertext, 0, 86, buf.length - 32); buf.copy(ciphertext, 0, 86, buf.length - 32);
var mac = new Buffer(32); var mac = Buffer.alloc(32);
buf.copy(mac, 0, buf.length - 32); buf.copy(mac, 0, buf.length - 32);
return { return {
iv: iv, iv: iv,