From 30b5380ce3c20e6f778d96b3a248a8a4f9e363b0 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 2 Jul 2014 15:23:48 -0700 Subject: [PATCH] remove rusha dep --- index.js | 10 ++++++---- package.json | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 9c2e6da..d66d7e4 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,16 @@ -var BitField = require('bitfield') var bencode = require('bencode') +var BitField = require('bitfield') +var bufferEqual = require('buffer-equal') +var crypto = require('crypto') var EventEmitter = require('events').EventEmitter var inherits = require('inherits') -var Rusha = require('rusha-browserify') // Fast SHA1 (works in browser) var BITFIELD_GROW = 1000 var PIECE_LENGTH = 16 * 1024 +// Return sha1 hash **as a buffer** function sha1 (buf) { - return (new Rusha()).digestFromBuffer(buf) + return crypto.createHash('sha1').update(buf).digest() } module.exports = function (metadata) { @@ -124,7 +126,7 @@ module.exports = function (metadata) { } catch (err) {} // check hash - if (this._infoHash && this._infoHash.toString('hex') !== sha1(metadata)) { + if (this._infoHash && !bufferEqual(this._infoHash, sha1(metadata))) { return false } diff --git a/package.json b/package.json index bab05a8..4934a9e 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "dependencies": { "bencode": "^0.6.0", "bitfield": "^1.0.1", - "inherits": "^2.0.1", - "rusha-browserify": "^0.7.3" + "buffer-equal": "0.0.1", + "inherits": "^2.0.1" }, "devDependencies": { "bittorrent-protocol": "^1.0.0",