summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bittorrent.cabal3
-rw-r--r--src/Data/Torrent.hs9
2 files changed, 7 insertions, 5 deletions
diff --git a/bittorrent.cabal b/bittorrent.cabal
index b625176d..4b1199b4 100644
--- a/bittorrent.cabal
+++ b/bittorrent.cabal
@@ -178,7 +178,8 @@ library
178 , vector >= 0.10 178 , vector >= 0.10
179 179
180 -- Hashing 180 -- Hashing
181 , cryptohash >= 0.10 181 , cryptonite
182 , memory
182 , hashable >= 1.2 183 , hashable >= 1.2
183 184
184 -- Codecs & Serialization 185 -- Codecs & Serialization
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index 8746fff5..1f70aea2 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -153,7 +153,7 @@ import Control.DeepSeq
153import Control.Exception 153import Control.Exception
154import Control.Lens 154import Control.Lens
155import Control.Monad 155import Control.Monad
156import Crypto.Hash.SHA1 as SHA1 156import Crypto.Hash
157#ifdef VERSION_bencoding 157#ifdef VERSION_bencoding
158import Data.BEncode as BE 158import Data.BEncode as BE
159import Data.BEncode.Types as BE 159import Data.BEncode.Types as BE
@@ -162,6 +162,7 @@ import Data.Bits
162#ifdef VERSION_bits_extras 162#ifdef VERSION_bits_extras
163import Data.Bits.Extras 163import Data.Bits.Extras
164#endif 164#endif
165import qualified Data.ByteArray as Bytes
165import Data.ByteString as BS 166import Data.ByteString as BS
166import Data.ByteString.Base16 as Base16 167import Data.ByteString.Base16 as Base16
167import Data.ByteString.Base32 as Base32 168import Data.ByteString.Base32 as Base32
@@ -645,7 +646,7 @@ pieceSize Piece {..} = fromIntegral (BL.length pieceData)
645 646
646-- | Get piece hash. 647-- | Get piece hash.
647hashPiece :: Piece BL.ByteString -> PieceHash 648hashPiece :: Piece BL.ByteString -> PieceHash
648hashPiece Piece {..} = SHA1.hashlazy pieceData 649hashPiece Piece {..} = Bytes.convert (hashlazy pieceData :: Digest SHA1)
649 650
650{----------------------------------------------------------------------- 651{-----------------------------------------------------------------------
651-- Piece control 652-- Piece control
@@ -728,7 +729,7 @@ checkPieceLazy :: PieceInfo -> Piece BL.ByteString -> Bool
728checkPieceLazy pinfo @ PieceInfo {..} Piece {..} 729checkPieceLazy pinfo @ PieceInfo {..} Piece {..}
729 = (fromIntegral (BL.length pieceData) == piPieceLength 730 = (fromIntegral (BL.length pieceData) == piPieceLength
730 || isLastPiece pinfo pieceIndex) 731 || isLastPiece pinfo pieceIndex)
731 && SHA1.hashlazy pieceData == pieceHash pinfo pieceIndex 732 && Bytes.convert (hashlazy pieceData :: Digest SHA1) == pieceHash pinfo pieceIndex
732 733
733{----------------------------------------------------------------------- 734{-----------------------------------------------------------------------
734-- Info dictionary 735-- Info dictionary
@@ -774,7 +775,7 @@ instance Hashable InfoDict where
774 775
775-- | Hash lazy bytestring using SHA1 algorithm. 776-- | Hash lazy bytestring using SHA1 algorithm.
776hashLazyIH :: BL.ByteString -> InfoHash 777hashLazyIH :: BL.ByteString -> InfoHash
777hashLazyIH = either (const (error msg)) id . safeConvert . SHA1.hashlazy 778hashLazyIH = either (const (error msg)) id . safeConvert . (Bytes.convert :: Digest SHA1 -> BS.ByteString) . hashlazy
778 where 779 where
779 msg = "Infohash.hash: impossible: SHA1 is always 20 bytes long" 780 msg = "Infohash.hash: impossible: SHA1 is always 20 bytes long"
780 781