Skip to content

Commit

Permalink
Replace Buffer constructor with static methods
Browse files Browse the repository at this point in the history
Fixes: ricmoo#68
  • Loading branch information
Gabriel Schulhof committed Sep 5, 2018
1 parent 64b5e74 commit f327eb2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ var key_192_array = new Uint8Array(key_192);
var key_256_array = new Uint8Array(key_256);

// or, you may use Buffer in node.js:
var key_128_buffer = new Buffer(key_128);
var key_192_buffer = new Buffer(key_192);
var key_256_buffer = new Buffer(key_256);
var key_128_buffer = Buffer.from(key_128);
var key_192_buffer = Buffer.from(key_192);
var key_256_buffer = Buffer.from(key_256);
```


Expand Down
8 changes: 4 additions & 4 deletions test/test-aes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ function makeTest(options) {

var plaintext = [];
for (var i = 0; i < options.plaintext.length; i++) {
plaintext.push(new Buffer(options.plaintext[i]));
plaintext.push(Buffer.from(options.plaintext[i]));
}

var key = new Buffer(options.key);
var key = Buffer.from(options.key);

var iv = null;
if (options.iv) { iv = new Buffer(options.iv); }
if (options.iv) { iv = Buffer.from(options.iv); }

var segmentSize = 0;
if (options.segmentSize) { segmentSize = options.segmentSize; }

var ciphertext = [];
for (var i = 0; i < options.encrypted.length; i++) {
ciphertext.push(new Buffer(options.encrypted[i]));
ciphertext.push(Buffer.from(options.encrypted[i]));
}


Expand Down
2 changes: 1 addition & 1 deletion test/test-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var nodeunit = require('nodeunit');
var slowCreateBuffer = require('../index')._arrayTest.coerceArray;

var testArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
var testBuffer = new Buffer(testArray);
var testBuffer = Buffer.from(testArray);

// We mimic some weird non-array-but-sortof-like-an-array object that people on
// obscure browsers seem to have problems with, for the purpose of testing our
Expand Down
4 changes: 2 additions & 2 deletions test/test-counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function bufferEquals(a, b) {

function makeTest (options) {
return function(test) {
var result = new Buffer(options.incrementResult, 'hex');
var result = Buffer.from(options.incrementResult, 'hex');

if (options.hasOwnProperty('nullish')) {
var counter = new aes.Counter(options.nullish);
Expand All @@ -37,7 +37,7 @@ function makeTest (options) {
}

if (options.bytes) {
var bytes = new Buffer(options.bytes, 'hex');
var bytes = Buffer.from(options.bytes, 'hex');

var counter = new aes.Counter(bytes);
counter.increment();
Expand Down
3 changes: 1 addition & 2 deletions test/test-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ var nodeunit = require('nodeunit');
var aes = require('../index');

function newBuffer(length) {
var buffer = new Buffer(length);
buffer.fill(42);
var buffer = Buffer.alloc(length);
return buffer;
}

Expand Down

0 comments on commit f327eb2

Please sign in to comment.