Permalink
Browse files

replace the openssl dependency by cryptohash.

- remove unused functions in Digest
- switch from io to pure code in couple of places.
  • Loading branch information...
1 parent 0dbba3f commit 6eba86f3c620de33721d7efda44809a6f6c17b99 @vincenthz vincenthz committed Oct 3, 2011
Showing with 8 additions and 23 deletions.
  1. +1 −1 Combinatorrent.cabal
  2. +4 −18 src/Digest.hs
  3. +1 −2 src/FS.hs
  4. +1 −1 src/Process/Peer.hs
  5. +1 −1 src/Protocol/BCode.hs
@@ -69,7 +69,7 @@ executable Combinatorrent
deepseq,
directory,
filepath,
- hopenssl,
+ cryptohash,
hslogger,
HTTP,
HUnit,
View
@@ -17,29 +17,15 @@ import Foreign.Ptr
import qualified Data.ByteString as B
import Data.ByteString.Unsafe
import qualified Data.ByteString.Lazy as L
-import qualified OpenSSL.Digest as SSL
+import qualified Crypto.Hash.SHA1 as SHA1
-- Consider newtyping this
type Digest = B.ByteString
instance NFData Digest
-digest :: L.ByteString -> IO B.ByteString
-digest bs = {-# SCC "sha1_digest" #-} B.pack <$> digestLBS SSL.SHA1 bs
+digest :: L.ByteString -> B.ByteString
+digest bs = {-# SCC "sha1_digest" #-} SHA1.hashlazy bs
-digestBS :: B.ByteString -> IO B.ByteString
+digestBS :: B.ByteString -> B.ByteString
digestBS bs = digest . L.fromChunks $ [bs]
-
-digestLBS :: SSL.MessageDigest -> L.ByteString -> IO [Word8]
-digestLBS mdType xs = SSL.mkDigest mdType $ evalStateT (updateLBS xs >> SSL.final)
-
-updateBS :: B.ByteString -> SSL.Digest ()
-updateBS bs = do
- SSL.DST ctx <- get
- _ <- liftIO $ unsafeUseAsCStringLen bs $
- \(ptr, len) -> SSL.digestUpdate ctx (castPtr ptr) (fromIntegral len)
- return ()
-
-updateLBS :: L.ByteString -> SSL.Digest ()
-updateLBS lbs = mapM_ updateBS chunked
- where chunked = {-# SCC "sha1_updateLBS_chunked" #-} L.toChunks lbs
View
@@ -136,8 +136,7 @@ checkPiece inf handles = {-# SCC "checkPiece" #-} do
do hSeek h AbsoluteSeek offs
L.hGet h (fromInteger size)
)
- dgs <- liftIO $ D.digest bs
- return (dgs == digest inf)
+ return (D.digest bs == digest inf)
-- | Create a MissingMap from a file handle and a piecemap. The system will read each part of
-- the file and then check it against the digest. It will create a map of what we are missing
View
@@ -781,7 +781,7 @@ allowedFast ip ihash sz n = generate n [] x []
| p `elem` pcs = generate k pcs hsh rest
| otherwise = generate (k-1) (p : pcs) hsh rest
generate k pcs hsh [] = do
- nhsh <- Digest.digestBS hsh
+ let nhsh = Digest.digestBS hsh
generate k pcs nhsh (genPieces nhsh)
genPieces hash | B.null hash = []
@@ -204,7 +204,7 @@ hashInfoDict bc =
Nothing -> fail "Could not find infoHash"
Just x -> return x
let encoded = encode ih
- digest $ L.fromChunks $ [encoded]
+ return $ digest $ L.fromChunks $ [encoded]
toPS :: String -> Path

0 comments on commit 6eba86f

Please sign in to comment.