From f16eb6f3e698f570acc3e461b552bfa214d2f1bb Mon Sep 17 00:00:00 2001 From: David Stephens Date: Sat, 28 Apr 2018 13:59:07 +0100 Subject: [PATCH] Fix Node.js 10 deprecation warnings --- .gitignore | 1 + core/archive_util.js | 4 ++-- core/art.js | 2 +- core/file_transfer.js | 4 ++-- core/fnv1a.js | 4 ++-- core/ftn_mail_packet.js | 20 ++++++++++---------- core/ftn_util.js | 2 +- core/sauce.js | 4 ++-- core/servers/login/telnet.js | 22 +++++++++++----------- core/telnet_bridge.js | 8 ++++---- core/user.js | 6 +++--- core/uuid_util.js | 6 +++--- 12 files changed, 42 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 5a58c717..28a19883 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.pem # Various directories +config/config.hjson logs/ db/ dropfiles/ diff --git a/core/archive_util.js b/core/archive_util.js index 8a4c388a..8ce2abc2 100644 --- a/core/archive_util.js +++ b/core/archive_util.js @@ -78,7 +78,7 @@ module.exports = class ArchiveUtil { Object.keys(Config.fileTypes).forEach(mimeType => { const fileType = Config.fileTypes[mimeType]; if(fileType.sig) { - fileType.sig = new Buffer(fileType.sig, 'hex'); + fileType.sig = Buffer.alloc(fileType.sig, 'hex'); fileType.offset = fileType.offset || 0; // :TODO: this is broken: sig is NOT this long, it's sig.length long; offset needs to allow for -negative values as well @@ -120,7 +120,7 @@ module.exports = class ArchiveUtil { return cb(err); } - const buf = new Buffer(this.longestSignature); + const buf = Buffer.from(this.longestSignature); fs.read(fd, buf, 0, buf.length, 0, (err, bytesRead) => { if(err) { return cb(err); diff --git a/core/art.js b/core/art.js index 546014bd..9234542d 100644 --- a/core/art.js +++ b/core/art.js @@ -288,7 +288,7 @@ function display(client, art, options, cb) { } if(!options.disableMciCache) { - artHash = xxhash.hash(new Buffer(art), 0xCAFEBABE); + artHash = xxhash.hash(Buffer.from(art), 0xCAFEBABE); // see if we have a mciMap cached for this art if(client.mciCache) { diff --git a/core/file_transfer.js b/core/file_transfer.js index 757eff8a..19388bab 100644 --- a/core/file_transfer.js +++ b/core/file_transfer.js @@ -374,7 +374,7 @@ exports.getModule = class TransferFileModule extends MenuModule { // needed for things like sz/rz if(external.escapeTelnet) { const tmp = data.toString('binary').replace(/\xff{2}/g, '\xff'); // de-escape - externalProc.write(new Buffer(tmp, 'binary')); + externalProc.write(Buffer.from(tmp, 'binary')); } else { externalProc.write(data); } @@ -384,7 +384,7 @@ exports.getModule = class TransferFileModule extends MenuModule { // needed for things like sz/rz if(external.escapeTelnet) { const tmp = data.toString('binary').replace(/\xff/g, '\xff\xff'); // escape - this.client.term.rawWrite(new Buffer(tmp, 'binary')); + this.client.term.rawWrite(Buffer.from(tmp, 'binary')); } else { this.client.term.rawWrite(data); } diff --git a/core/fnv1a.js b/core/fnv1a.js index 743986d6..ce1fe105 100644 --- a/core/fnv1a.js +++ b/core/fnv1a.js @@ -19,7 +19,7 @@ module.exports = class FNV1a { } if(_.isString(data)) { - data = new Buffer(data); + data = Buffer.from(data); } if(!Buffer.isBuffer(data)) { @@ -38,7 +38,7 @@ module.exports = class FNV1a { digest(encoding) { encoding = encoding || 'binary'; - let buf = new Buffer(4); + let buf = Buffer.alloc(4); buf.writeInt32BE(this.hash & 0xffffffff, 0); return buf.toString(encoding); } diff --git a/core/ftn_mail_packet.js b/core/ftn_mail_packet.js index bb72c40a..5db02227 100644 --- a/core/ftn_mail_packet.js +++ b/core/ftn_mail_packet.js @@ -26,7 +26,7 @@ const FTN_PACKET_MESSAGE_TYPE = 2; const FTN_PACKET_BAUD_TYPE_2_2 = 2; // SAUCE magic header + version ("00") -const FTN_MESSAGE_SAUCE_HEADER = new Buffer('SAUCE00'); +const FTN_MESSAGE_SAUCE_HEADER = Buffer.from('SAUCE00'); const FTN_MESSAGE_KLUDGE_PREFIX = '\x01'; @@ -273,7 +273,7 @@ function Packet(options) { }; this.getPacketHeaderBuffer = function(packetHeader) { - let buffer = new Buffer(FTN_PACKET_HEADER_SIZE); + let buffer = Buffer.from(FTN_PACKET_HEADER_SIZE); buffer.writeUInt16LE(packetHeader.origNode, 0); buffer.writeUInt16LE(packetHeader.destNode, 2); @@ -311,7 +311,7 @@ function Packet(options) { }; this.writePacketHeader = function(packetHeader, ws) { - let buffer = new Buffer(FTN_PACKET_HEADER_SIZE); + let buffer = Buffer.from(FTN_PACKET_HEADER_SIZE); buffer.writeUInt16LE(packetHeader.origNode, 0); buffer.writeUInt16LE(packetHeader.destNode, 2); @@ -447,8 +447,8 @@ function Packet(options) { // Also according to the spec, the deprecated "CHARSET" value may be used // :TODO: Look into CHARSET more - should we bother supporting it? // :TODO: See encodingFromHeader() for CHRS/CHARSET support @ https://github.com/Mithgol/node-fidonet-jam - const FTN_CHRS_PREFIX = new Buffer( [ 0x01, 0x43, 0x48, 0x52, 0x53, 0x3a, 0x20 ] ); // "\x01CHRS:" - const FTN_CHRS_SUFFIX = new Buffer( [ 0x0d ] ); + const FTN_CHRS_PREFIX = Buffer.from( [ 0x01, 0x43, 0x48, 0x52, 0x53, 0x3a, 0x20 ] ); // "\x01CHRS:" + const FTN_CHRS_SUFFIX = Buffer.from( [ 0x0d ] ); let chrsPrefixIndex = messageBodyBuffer.indexOf(FTN_CHRS_PREFIX); if(chrsPrefixIndex < 0) { @@ -724,7 +724,7 @@ function Packet(options) { buf.writeUInt16LE(message.meta.FtnProperty.ftn_attr_flags, 10); buf.writeUInt16LE(message.meta.FtnProperty.ftn_cost, 12); - const dateTimeBuffer = new Buffer(ftn.getDateTimeString(message.modTimestamp) + '\0'); + const dateTimeBuffer = Buffer.from(ftn.getDateTimeString(message.modTimestamp) + '\0'); dateTimeBuffer.copy(buf, 14); }; @@ -747,7 +747,7 @@ function Packet(options) { async.waterfall( [ function prepareHeaderAndKludges(callback) { - const basicHeader = new Buffer(34); + const basicHeader = Buffer.from(34); self.writeMessageHeader(message, basicHeader); // @@ -864,7 +864,7 @@ function Packet(options) { }; this.writeMessage = function(message, ws, options) { - let basicHeader = new Buffer(34); + let basicHeader = Buffer.from(34); self.writeMessageHeader(message, basicHeader); ws.write(basicHeader); @@ -1054,7 +1054,7 @@ Packet.prototype.writeTerminator = function(ws) { // From FTS-0001.016: // "A pseudo-message beginning with the word 0000H signifies the end of the packet." // - ws.write(new Buffer( [ 0x00, 0x00 ] )); // final extra null term + ws.write(Buffer.from( [ 0x00, 0x00 ] )); // final extra null term return 2; }; @@ -1074,7 +1074,7 @@ Packet.prototype.writeStream = function(ws, messages, options) { }); if(true === options.terminatePacket) { - ws.write(new Buffer( [ 0 ] )); // final extra null term + ws.write(Buffer.from( [ 0 ] )); // final extra null term } }; diff --git a/core/ftn_util.js b/core/ftn_util.js index 03040484..e40d2687 100644 --- a/core/ftn_util.js +++ b/core/ftn_util.js @@ -46,7 +46,7 @@ exports.getQuotePrefix = getQuotePrefix; // See list here: https://github.com/Mithgol/node-fidonet-jam function stringToNullPaddedBuffer(s, bufLen) { - let buffer = new Buffer(bufLen).fill(0x00); + let buffer = Buffer.alloc(bufLen).fill(0x00); let enc = iconv.encode(s, 'CP437').slice(0, bufLen); for(let i = 0; i < enc.length; ++i) { buffer[i] = enc[i]; diff --git a/core/sauce.js b/core/sauce.js index 9ee75b47..e0182ae7 100644 --- a/core/sauce.js +++ b/core/sauce.js @@ -10,10 +10,10 @@ const { Parser } = require('binary-parser'); exports.readSAUCE = readSAUCE; const SAUCE_SIZE = 128; -const SAUCE_ID = new Buffer([0x53, 0x41, 0x55, 0x43, 0x45]); // 'SAUCE' +const SAUCE_ID = Buffer.from([0x53, 0x41, 0x55, 0x43, 0x45]); // 'SAUCE' // :TODO read comments -//const COMNT_ID = new Buffer([0x43, 0x4f, 0x4d, 0x4e, 0x54]); // 'COMNT' +//const COMNT_ID = Buffer.from([0x43, 0x4f, 0x4d, 0x4e, 0x54]); // 'COMNT' exports.SAUCE_SIZE = SAUCE_SIZE; // :TODO: SAUCE should be a class diff --git a/core/servers/login/telnet.js b/core/servers/login/telnet.js index 6ffb49a9..3c585c84 100644 --- a/core/servers/login/telnet.js +++ b/core/servers/login/telnet.js @@ -159,8 +159,8 @@ const NEW_ENVIRONMENT_COMMANDS = { USERVAR : 3, }; -const IAC_BUF = new Buffer([ COMMANDS.IAC ]); -const IAC_SE_BUF = new Buffer([ COMMANDS.IAC, COMMANDS.SE ]); +const IAC_BUF = Buffer.from([ COMMANDS.IAC ]); +const IAC_SE_BUF = Buffer.from([ COMMANDS.IAC, COMMANDS.SE ]); const COMMAND_NAMES = Object.keys(COMMANDS).reduce(function(names, name) { names[COMMANDS[name]] = name.toLowerCase(); @@ -766,7 +766,7 @@ TelnetClient.prototype.handleMiscCommand = function(evt) { }; TelnetClient.prototype.requestTerminalType = function() { - const buf = new Buffer( [ + const buf = Buffer.from( [ COMMANDS.IAC, COMMANDS.SB, OPTIONS.TERMINAL_TYPE, @@ -777,10 +777,10 @@ TelnetClient.prototype.requestTerminalType = function() { }; const WANTED_ENVIRONMENT_VAR_BUFS = [ - new Buffer( 'LINES' ), - new Buffer( 'COLUMNS' ), - new Buffer( 'TERM' ), - new Buffer( 'TERM_PROGRAM' ) + Buffer.from( 'LINES' ), + Buffer.from( 'COLUMNS' ), + Buffer.from( 'TERM' ), + Buffer.from( 'TERM_PROGRAM' ) ]; TelnetClient.prototype.requestNewEnvironment = function() { @@ -793,7 +793,7 @@ TelnetClient.prototype.requestNewEnvironment = function() { const self = this; const bufs = buffers(); - bufs.push(new Buffer( [ + bufs.push(Buffer.from( [ COMMANDS.IAC, COMMANDS.SB, OPTIONS.NEW_ENVIRONMENT, @@ -801,10 +801,10 @@ TelnetClient.prototype.requestNewEnvironment = function() { )); for(let i = 0; i < WANTED_ENVIRONMENT_VAR_BUFS.length; ++i) { - bufs.push(new Buffer( [ NEW_ENVIRONMENT_COMMANDS.VAR ] ), WANTED_ENVIRONMENT_VAR_BUFS[i] ); + bufs.push(Buffer.from( [ NEW_ENVIRONMENT_COMMANDS.VAR ] ), WANTED_ENVIRONMENT_VAR_BUFS[i] ); } - bufs.push(new Buffer([ NEW_ENVIRONMENT_COMMANDS.USERVAR, COMMANDS.IAC, COMMANDS.SE ])); + bufs.push(Buffer.from([ NEW_ENVIRONMENT_COMMANDS.USERVAR, COMMANDS.IAC, COMMANDS.SE ])); self.output.write(bufs.toBuffer()); @@ -836,7 +836,7 @@ Object.keys(OPTIONS).forEach(function(name) { const code = OPTIONS[name]; Command.prototype[name.toLowerCase()] = function() { - const buf = new Buffer(3); + const buf = Buffer.alloc(3); buf[0] = COMMANDS.IAC; buf[1] = this.command; buf[2] = code; diff --git a/core/telnet_bridge.js b/core/telnet_bridge.js index 95ace6c6..150996dd 100644 --- a/core/telnet_bridge.js +++ b/core/telnet_bridge.js @@ -33,7 +33,7 @@ exports.moduleInfo = { author : 'Andrew Pamment', }; -const IAC_DO_TERM_TYPE = new Buffer( [ 255, 253, 24 ] ); +const IAC_DO_TERM_TYPE = Buffer.from( [ 255, 253, 24 ] ); class TelnetClientConnection extends EventEmitter { constructor(client) { @@ -103,7 +103,7 @@ class TelnetClientConnection extends EventEmitter { // let bufs = buffers(); - bufs.push(new Buffer( + bufs.push(Buffer.from( [ 255, // IAC 250, // SB @@ -113,8 +113,8 @@ class TelnetClientConnection extends EventEmitter { )); bufs.push( - new Buffer(this.client.term.termType), // e.g. "ansi" - new Buffer( [ 255, 240 ] ) // IAC, SE + Buffer.from(this.client.term.termType), // e.g. "ansi" + Buffer.from( [ 255, 240 ] ) // IAC, SE ); return bufs.toBuffer(); diff --git a/core/user.js b/core/user.js index 76c493ea..59f150bb 100644 --- a/core/user.js +++ b/core/user.js @@ -130,8 +130,8 @@ module.exports = class User { // // Use constant time comparison here for security feel-goods // - const passDkBuf = new Buffer(passDk, 'hex'); - const propsDkBuf = new Buffer(propsDk, 'hex'); + const passDkBuf = Buffer.from(passDk, 'hex'); + const propsDkBuf = Buffer.from(propsDk, 'hex'); if(passDkBuf.length !== propsDkBuf.length) { return callback(Errors.AccessDenied('Invalid password')); @@ -595,7 +595,7 @@ module.exports = class User { } static generatePasswordDerivedKey(password, salt, cb) { - password = new Buffer(password).toString('hex'); + password = Buffer.from(password).toString('hex'); crypto.pbkdf2(password, salt, User.PBKDF2.iterations, User.PBKDF2.keyLen, 'sha1', (err, dk) => { if(err) { diff --git a/core/uuid_util.js b/core/uuid_util.js index de64ec30..9af449dd 100644 --- a/core/uuid_util.js +++ b/core/uuid_util.js @@ -11,17 +11,17 @@ function createNamedUUID(namespaceUuid, key) { // https://github.com/download13/uuidv5/blob/master/uuid.js // if(!Buffer.isBuffer(namespaceUuid)) { - namespaceUuid = new Buffer(namespaceUuid); + namespaceUuid = Buffer.from(namespaceUuid); } if(!Buffer.isBuffer(key)) { - key = new Buffer(key); + key = Buffer.from(key); } let digest = createHash('sha1').update( Buffer.concat( [ namespaceUuid, key ] )).digest(); - let u = new Buffer(16); + let u = Buffer.alloc(16); // bbbb - bb - bb - bb - bbbbbb digest.copy(u, 0, 0, 4); // time_low