]> git.rkrishnan.org Git - functorrent.git/blobdiff - src/FuncTorrent/Metainfo.hs
Move things around
[functorrent.git] / src / FuncTorrent / Metainfo.hs
index 4a95a70a9f980209cd7e5bf9300e0d900cc3a939..61699a3319e33f6c7a375eec9bf55c9c769f698f 100644 (file)
@@ -1,16 +1,18 @@
 module FuncTorrent.Metainfo
     (Info(..),
      Metainfo(..),
-     mkMetaInfo,
-     mkInfo
+     infoHash,
+     mkInfo,
+     mkMetaInfo
     ) where
 
 import Prelude hiding (lookup)
 import Data.ByteString.Char8 (ByteString, unpack)
 import Data.Map as M ((!), lookup)
+import Crypto.Hash.SHA1 (hash)
 import Data.Maybe (maybeToList)
 
-import FuncTorrent.Bencode (BVal(..), bstrToString)
+import FuncTorrent.Bencode (BVal(..), InfoDict, encode, bstrToString)
 
 -- only single file mode supported for the time being.
 data Info = Info { pieceLength :: !Integer
@@ -79,3 +81,9 @@ getAnnounceList (Just (Blist l)) = map (\s -> case s of
                                                _ -> "") l
 
 getAnnounceList (Just (Bdict _)) = []
+
+-- | Info hash is urlencoded 20 byte SHA1 hash of the value of the info key from
+-- the Metainfo file. Note that the value will be a bencoded dictionary, given
+-- the definition of the info key above. TODO: `Metainfo -> ByteString`
+infoHash :: InfoDict -> ByteString
+infoHash m = hash . encode $ (m ! "info")