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
_ -> "") 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")