Skip to content
Merged
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
2 changes: 2 additions & 0 deletions lib/MultipartDataGenerator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var Buffer = require('safe-buffer').Buffer;

// Method for formatting HTTP body for the multipart/form-data specification
// Mostly taken from Fermata.js
// https://github.com/natevw/fermata/blob/5d9732a33d776ce925013a265935facd1626cc88/fermata.js#L315-L343
Expand Down
26 changes: 3 additions & 23 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var Buffer = require('safe-buffer').Buffer;
var qs = require('qs');
var crypto = require('crypto');

Expand Down Expand Up @@ -131,8 +132,8 @@ var utils = module.exports = {
* Secure compare, from https://github.com/freewil/scmp
*/
secureCompare: function(a, b) {
var a = asBuffer(a);
var b = asBuffer(b);
var a = Buffer.from(a);
var b = Buffer.from(b);

// return early here if buffer lengths are not equal since timingSafeEqual
// will throw if buffer lengths are not equal
Expand Down Expand Up @@ -172,24 +173,3 @@ var utils = module.exports = {
return obj;
},
};

function asBuffer(thing) {
if (Buffer.isBuffer(thing)) {
return thing;
}

if (Buffer.from) {
// Buffer.from fix for node versions prior to 4.5.x
try {
return Buffer.from(thing);
} catch (e) {
if (e instanceof TypeError) {
return new Buffer(thing);
} else {
throw e;
}
}
} else {
return new Buffer(thing);
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"dependencies": {
"bluebird": "^3.5.0",
"lodash.isplainobject": "^4.0.6",
"qs": "~6.5.1"
"qs": "~6.5.1",
"safe-buffer": "^5.1.1"
},
"license": "MIT",
"scripts": {
Expand Down