Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Buffer.(from|alloc) instead of deprecated Buffer API #103

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/asn1/base/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const inherits = require('inherits');
const Reporter = require('../base').Reporter;
const Buffer = require('buffer').Buffer;
const Buffer = require('safer-buffer').Buffer;

function DecoderBuffer(base, options) {
Reporter.call(this, options);
Expand Down Expand Up @@ -92,7 +92,7 @@ exports.EncoderBuffer = EncoderBuffer;

EncoderBuffer.prototype.join = function join(out, offset) {
if (!out)
out = new Buffer(this.length);
out = Buffer.alloc(this.length);
if (!offset)
offset = 0;

Expand Down
4 changes: 2 additions & 2 deletions lib/asn1/decoders/pem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const inherits = require('inherits');
const Buffer = require('buffer').Buffer;
const Buffer = require('safer-buffer').Buffer;

const DERDecoder = require('./der');

Expand Down Expand Up @@ -46,6 +46,6 @@ PEMDecoder.prototype.decode = function decode(data, options) {
// Remove excessive symbols
base64.replace(/[^a-z0-9+/=]+/gi, '');

const input = new Buffer(base64, 'base64');
const input = Buffer.from(base64, 'base64');
return DERDecoder.prototype.decode.call(this, input, options);
};
16 changes: 8 additions & 8 deletions lib/asn1/encoders/der.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const inherits = require('inherits');
const Buffer = require('buffer').Buffer;
const Buffer = require('safer-buffer').Buffer;

const asn1 = require('../../asn1');
const base = asn1.base;
Expand Down Expand Up @@ -39,7 +39,7 @@ DERNode.prototype._encodeComposite = function encodeComposite(tag,

// Short form
if (content.length < 0x80) {
const header = new Buffer(2);
const header = Buffer.alloc(2);
header[0] = encodedTag;
header[1] = content.length;
return this._createEncoderBuffer([ header, content ]);
Expand All @@ -51,7 +51,7 @@ DERNode.prototype._encodeComposite = function encodeComposite(tag,
for (let i = content.length; i >= 0x100; i >>= 8)
lenOctets++;

const header = new Buffer(1 + 1 + lenOctets);
const header = Buffer.alloc(1 + 1 + lenOctets);
header[0] = encodedTag;
header[1] = 0x80 | lenOctets;

Expand All @@ -65,7 +65,7 @@ DERNode.prototype._encodeStr = function encodeStr(str, tag) {
if (tag === 'bitstr') {
return this._createEncoderBuffer([ str.unused | 0, str.data ]);
} else if (tag === 'bmpstr') {
const buf = new Buffer(str.length * 2);
const buf = Buffer.alloc(str.length * 2);
for (let i = 0; i < str.length; i++) {
buf.writeUInt16BE(str.charCodeAt(i), i * 2);
}
Expand Down Expand Up @@ -130,7 +130,7 @@ DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) {
size++;
}

const objid = new Buffer(size);
const objid = Buffer.alloc(size);
let offset = objid.length - 1;
for (let i = id.length - 1; i >= 0; i--) {
let ident = id[i];
Expand Down Expand Up @@ -201,15 +201,15 @@ DERNode.prototype._encodeInt = function encodeInt(num, values) {
if (!num.sign && numArray[0] & 0x80) {
numArray.unshift(0);
}
num = new Buffer(numArray);
num = Buffer.from(numArray);
}

if (Buffer.isBuffer(num)) {
let size = num.length;
if (num.length === 0)
size++;

const out = new Buffer(size);
const out = Buffer.alloc(size);
num.copy(out);
if (num.length === 0)
out[0] = 0;
Expand All @@ -235,7 +235,7 @@ DERNode.prototype._encodeInt = function encodeInt(num, values) {
out.unshift(0);
}

return this._createEncoderBuffer(new Buffer(out));
return this._createEncoderBuffer(Buffer.from(out));
};

DERNode.prototype._encodeBool = function encodeBool(value) {
Expand Down
Loading