time ==1.4.2,
bytestring,
doctest,
- HTTP >=4000.2.1
+ HTTP >=4000.2.1,
+ cryptohash
hs-source-dirs: src
ghc-options: -Wall -fwarn-incomplete-patterns
default-language: Haskell2010
\ No newline at end of file
case (Benc.decode torrentStr) of
Right d -> case (MInfo.mkMetaInfo d) of
Nothing -> putStrLn "parse error"
- Just m -> putStrLn (show m)
+ Just m -> do
+ let (Benc.Bdict d') = d
+ putStrLn (show m)
+ putStrLn (MInfo.infoHash d')
Left e -> printError e
putStrLn "done"
import qualified Bencode as Benc
import qualified Data.ByteString.Char8 as BC
import qualified Data.Map as M
+import qualified Crypto.Hash as H
+import qualified Crypto.Hash.SHA1 as SHA1
import Data.Time.Clock
-- only single file mode supported for the time being.
, encoding = maybeBstrToString encoding' }
mkMetaInfo _ = Nothing
+infoHash :: (M.Map Benc.BVal Benc.BVal) -> String
+infoHash m = let info = m M.! (Benc.Bstr (BC.pack "info"))
+ in show $ SHA1.hash $ BC.pack $ Benc.encode info