remove rusha dep
This commit is contained in:
parent
6c7adecf25
commit
30b5380ce3
10
index.js
10
index.js
|
@ -1,14 +1,16 @@
|
||||||
var BitField = require('bitfield')
|
|
||||||
var bencode = require('bencode')
|
var bencode = require('bencode')
|
||||||
|
var BitField = require('bitfield')
|
||||||
|
var bufferEqual = require('buffer-equal')
|
||||||
|
var crypto = require('crypto')
|
||||||
var EventEmitter = require('events').EventEmitter
|
var EventEmitter = require('events').EventEmitter
|
||||||
var inherits = require('inherits')
|
var inherits = require('inherits')
|
||||||
var Rusha = require('rusha-browserify') // Fast SHA1 (works in browser)
|
|
||||||
|
|
||||||
var BITFIELD_GROW = 1000
|
var BITFIELD_GROW = 1000
|
||||||
var PIECE_LENGTH = 16 * 1024
|
var PIECE_LENGTH = 16 * 1024
|
||||||
|
|
||||||
|
// Return sha1 hash **as a buffer**
|
||||||
function sha1 (buf) {
|
function sha1 (buf) {
|
||||||
return (new Rusha()).digestFromBuffer(buf)
|
return crypto.createHash('sha1').update(buf).digest()
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function (metadata) {
|
module.exports = function (metadata) {
|
||||||
|
@ -124,7 +126,7 @@ module.exports = function (metadata) {
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
|
|
||||||
// check hash
|
// check hash
|
||||||
if (this._infoHash && this._infoHash.toString('hex') !== sha1(metadata)) {
|
if (this._infoHash && !bufferEqual(this._infoHash, sha1(metadata))) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bencode": "^0.6.0",
|
"bencode": "^0.6.0",
|
||||||
"bitfield": "^1.0.1",
|
"bitfield": "^1.0.1",
|
||||||
"inherits": "^2.0.1",
|
"buffer-equal": "0.0.1",
|
||||||
"rusha-browserify": "^0.7.3"
|
"inherits": "^2.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"bittorrent-protocol": "^1.0.0",
|
"bittorrent-protocol": "^1.0.0",
|
||||||
|
|
Loading…
Reference in New Issue