Fix buffer warnings

This commit is contained in:
Girish Ramakrishnan
2019-03-21 20:06:14 -07:00
parent e9108ae3f8
commit 81b721be2b
4 changed files with 10 additions and 10 deletions
+2 -2
View File
@@ -628,7 +628,7 @@ function install(data, user, auditSource, callback) {
if (icon) {
if (!validator.isBase64(icon)) return callback(new AppsError(AppsError.BAD_FIELD, 'icon is not base64'));
if (!safe.fs.writeFileSync(path.join(paths.APP_ICONS_DIR, appId + '.png'), new Buffer(icon, 'base64'))) {
if (!safe.fs.writeFileSync(path.join(paths.APP_ICONS_DIR, appId + '.png'), Buffer.from(icon, 'base64'))) {
return callback(new AppsError(AppsError.INTERNAL_ERROR, 'Error saving icon:' + safe.error.message));
}
}
@@ -886,7 +886,7 @@ function update(appId, data, auditSource, callback) {
if (data.icon) {
if (!validator.isBase64(data.icon)) return callback(new AppsError(AppsError.BAD_FIELD, 'icon is not base64'));
if (!safe.fs.writeFileSync(path.join(paths.APP_ICONS_DIR, appId + '.png'), new Buffer(data.icon, 'base64'))) {
if (!safe.fs.writeFileSync(path.join(paths.APP_ICONS_DIR, appId + '.png'), Buffer.from(data.icon, 'base64'))) {
return callback(new AppsError(AppsError.INTERNAL_ERROR, 'Error saving icon:' + safe.error.message));
}
} else {
+1 -1
View File
@@ -80,7 +80,7 @@ function urlBase64Encode(string) {
}
function b64(str) {
var buf = util.isBuffer(str) ? str : new Buffer(str);
var buf = util.isBuffer(str) ? str : Buffer.from(str);
return urlBase64Encode(buf.toString('base64'));
}
+2 -2
View File
@@ -97,9 +97,9 @@ function finalSend(results, req, res, next) {
var resultCookie;
if (last < max) {
resultCookie = new Buffer(last.toString());
resultCookie = Buffer.from(last.toString());
} else {
resultCookie = new Buffer('');
resultCookie = Buffer.from('');
}
res.controls.push(new ldap.PagedResultsControl({
+5 -5
View File
@@ -192,7 +192,7 @@ function create(username, password, email, displayName, options, auditSource, ca
username: username,
email: email,
fallbackEmail: email, // for new users the fallbackEmail is also the default email
password: new Buffer(derivedKey, 'binary').toString('hex'),
password: Buffer.from(derivedKey, 'binary').toString('hex'),
salt: salt.toString('hex'),
createdAt: now,
modifiedAt: now,
@@ -249,11 +249,11 @@ function verify(userId, password, callback) {
return callback(null, user);
}
var saltBinary = new Buffer(user.salt, 'hex');
var saltBinary = Buffer.from(user.salt, 'hex');
crypto.pbkdf2(password, saltBinary, CRYPTO_ITERATIONS, CRYPTO_KEY_LENGTH, CRYPTO_DIGEST, function (error, derivedKey) {
if (error) return callback(new UsersError(UsersError.INTERNAL_ERROR, error));
var derivedKeyHex = new Buffer(derivedKey, 'binary').toString('hex');
var derivedKeyHex = Buffer.from(derivedKey, 'binary').toString('hex');
if (derivedKeyHex !== user.password) return callback(new UsersError(UsersError.WRONG_PASSWORD));
callback(null, user);
@@ -513,12 +513,12 @@ function setPassword(userId, newPassword, callback) {
if (config.isDemo() && user.username === constants.DEMO_USERNAME) return callback(new UsersError(UsersError.BAD_FIELD, 'Not allowed in demo mode'));
var saltBuffer = new Buffer(user.salt, 'hex');
var saltBuffer = Buffer.from(user.salt, 'hex');
crypto.pbkdf2(newPassword, saltBuffer, CRYPTO_ITERATIONS, CRYPTO_KEY_LENGTH, CRYPTO_DIGEST, function (error, derivedKey) {
if (error) return callback(new UsersError(UsersError.INTERNAL_ERROR, error));
user.modifiedAt = (new Date()).toISOString();
user.password = new Buffer(derivedKey, 'binary').toString('hex');
user.password = Buffer.from(derivedKey, 'binary').toString('hex');
user.resetToken = '';
userdb.update(userId, user, function (error) {