Browse Source

Stop using deprecated new Buffer()

Caleb James DeLisle 5 years ago
parent
commit
ec65c2f17c
3 changed files with 6 additions and 6 deletions
  1. 2 2
      test/testcjdroute.js
  2. 2 2
      tools/lib/cjdnsadmin/cjdnsadmin.js
  3. 2 2
      tools/lib/publicToIp6.js

+ 2 - 2
test/testcjdroute.js

@@ -87,8 +87,8 @@ var mkFuzzCase = function (inFile, outPath, testId, cb) {
         if (err) { throw err; }
         ret = ret.replace(/#[^\n]*\n/g, '');
         ret = ret.replace(/[\s]*/g, '');
-        var out = new Buffer(ret, 'hex');
-        var id = new Buffer(4);
+        var out = Buffer.from(ret, 'hex');
+        var id = Buffer.alloc(4);
         id.writeInt32BE(testId, 0);
         Fs.writeFile(outPath, Buffer.concat([id, out]), function (err) {
             if (err) { throw err; }

+ 2 - 2
tools/lib/cjdnsadmin/cjdnsadmin.js

@@ -43,7 +43,7 @@ var sendmsg = function (sock, addr, port, msg, txid, callback) {
 
 var callFunc = function (sock, addr, port, pass, func, args, callback) {
     var cookieTxid = String(sock.counter++);
-    var cookieMsg = new Buffer(Bencode.encode({'q':'cookie','txid':cookieTxid}));
+    var cookieMsg = Buffer.from(Bencode.encode({'q':'cookie','txid':cookieTxid}));
     sendmsg(sock, addr, port, cookieMsg, cookieTxid, function (err, ret) {
         if (err) { callback(err); return; }
         var cookie = ret.cookie;
@@ -64,7 +64,7 @@ var callFunc = function (sock, addr, port, pass, func, args, callback) {
             json.hash = Crypto.createHash('sha256').update(pass + cookie).digest('hex');
             json.hash = Crypto.createHash('sha256').update(Bencode.encode(json)).digest('hex');
         }
-        sendmsg(sock, addr, port, new Buffer(Bencode.encode(json)), json.txid, callback);
+        sendmsg(sock, addr, port, Buffer.from(Bencode.encode(json)), json.txid, callback);
     });
 };
 

+ 2 - 2
tools/lib/publicToIp6.js

@@ -56,14 +56,14 @@ var Base32_decode = function (input) {
         throw new Error("bits is " + bits + " and nextByte is " + nextByte);
     }
 
-    return new Buffer(output);
+    return Buffer.from(output);
 };
 
 var convert = module.exports.convert = function (pubKey) {
     if (pubKey.substring(pubKey.length-2) !== ".k") { throw new Error("key does not end with .k"); }
     keyBytes = Base32_decode(pubKey.substring(0, pubKey.length-2));
     //console.log(keyBytes.toString('hex'));
-    var hashOneBuff = new Buffer(Crypto.createHash('sha512').update(keyBytes).digest('hex'), 'hex');
+    var hashOneBuff = Buffer.from(Crypto.createHash('sha512').update(keyBytes).digest('hex'), 'hex');
     var hashTwo = Crypto.createHash('sha512').update(hashOneBuff).digest('hex');
     var first16 = hashTwo.substring(0,32);
     var out = [];