Skip to content

Commit

Permalink
Deprecate node v6 new Buffer calls in favor of Buffer.from.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 authored and davidlehn committed May 22, 2019
1 parent 8235682 commit 8de3c0f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ var signature = ED25519.sign({
// sign a message passed as a buffer
var signature = ED25519.sign({
// also accepts a forge ByteBuffer or Uint8Array
message: new Buffer('test', 'utf8'),
message: Buffer.from('test', 'utf8'),
privateKey: privateKey
});

Expand All @@ -930,7 +930,7 @@ var verified = ED25519.verify({
// sign a message passed as a buffer
var verified = ED25519.verify({
// also accepts a forge ByteBuffer or Uint8Array
message: new Buffer('test', 'utf8'),
message: Buffer.from('test', 'utf8'),
// node.js Buffer, Uint8Array, forge ByteBuffer, or binary string
signature: signature,
// node.js Buffer, Uint8Array, forge ByteBuffer, or binary string
Expand Down Expand Up @@ -1961,11 +1961,11 @@ bytes.getBytes(/* count */);
// convert a forge buffer into a Node.js Buffer
// make sure you specify the encoding as 'binary'
var forgeBuffer = forge.util.createBuffer();
var nodeBuffer = new Buffer(forgeBuffer.getBytes(), 'binary');
var nodeBuffer = Buffer.from(forgeBuffer.getBytes(), 'binary');

// convert a Node.js Buffer into a forge buffer
// make sure you specify the encoding as 'binary'
var nodeBuffer = new Buffer();
var nodeBuffer = Buffer.alloc(10);
var forgeBuffer = forge.util.createBuffer(nodeBuffer.toString('binary'));

// parse a URL
Expand Down
2 changes: 1 addition & 1 deletion lib/asn1.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ function _fromDer(bytes, remaining, depth, options) {
}

// add BIT STRING contents if available
var asn1Options = bitStringContents === undefined ? null : {
var asn1Options = bitStringContents === undefined ? null : {
bitStringContents: bitStringContents
};

Expand Down
4 changes: 2 additions & 2 deletions lib/ed25519.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function messageToNativeBuffer(options) {

if(typeof message === 'string') {
if(typeof Buffer !== 'undefined') {
return new Buffer(message, encoding);
return Buffer.from(message, encoding);
}
message = new ByteBuffer(message, encoding);
} else if(!(message instanceof ByteBuffer)) {
Expand Down Expand Up @@ -217,7 +217,7 @@ function sha512(msg, msgLen) {
md.update(buffer.getBytes(msgLen), 'binary');
var hash = md.digest().getBytes();
if(typeof Buffer !== 'undefined') {
return new Buffer(hash, 'binary');
return Buffer.from(hash, 'binary');
}
var out = new NativeBuffer(ed25519.constants.HASH_BYTE_LENGTH);
for(var i = 0; i < 64; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions lib/pbkdf2.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ module.exports = forge.pbkdf2 = pkcs5.pbkdf2 = function(
// default prf to SHA-1
md = 'sha1';
}
p = new Buffer(p, 'binary');
s = new Buffer(s, 'binary');
p = Buffer.from(p, 'binary');
s = Buffer.from(s, 'binary');
if(!callback) {
if(crypto.pbkdf2Sync.length === 4) {
return crypto.pbkdf2Sync(p, s, c, dkLen).toString('binary');
Expand Down
6 changes: 3 additions & 3 deletions tests/benchmarks/so-44303784.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ function test_forge_chunk(bytes, chunkSize) {
}

function test_node(bytes) {
const bufb = new Buffer(bytes, 'binary');
const ivb = new Buffer(iv, 'binary');
const keyb = new Buffer(key, 'binary');
const bufb = Buffer.from(bytes, 'binary');
const ivb = Buffer.from(iv, 'binary');
const keyb = Buffer.from(key, 'binary');

const start = new Date();

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/ed25519.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var UTIL = require('../../lib/util');
var seed = md.digest().getBytes();
var kp = ED25519.generateKeyPair({seed: seed});
var signature = ED25519.sign({
message: new Buffer('test', 'utf8'),
message: Buffer.from('test', 'utf8'),
privateKey: kp.privateKey
});
ASSERT.equal(eb64(signature), b64Signature);
Expand Down Expand Up @@ -179,7 +179,7 @@ var UTIL = require('../../lib/util');
var seed = md.digest().getBytes();
var kp = ED25519.generateKeyPair({seed: seed});

var signature = new Buffer(db64(b64Signature).getBytes(), 'binary');
var signature = Buffer.from(db64(b64Signature).getBytes(), 'binary');

var verified = ED25519.verify({
message: 'test',
Expand Down

0 comments on commit 8de3c0f

Please sign in to comment.