module FuncTorrent.Metainfo
(Info(..),
Metainfo(..),
- infoHash,
mkInfo,
mkMetaInfo
) where
import Crypto.Hash.SHA1 (hash)
import Data.Maybe (maybeToList)
-import FuncTorrent.Bencode (BVal(..), InfoDict, encode, bstrToString, bValToInteger)
+import FuncTorrent.Bencode (BVal(..), encode, bstrToString, bValToInteger)
-- only single file mode supported for the time being.
data Info = Info { pieceLength :: !Integer
, comment :: !(Maybe String)
, createdBy :: !(Maybe String)
, encoding :: !(Maybe String)
+ , infoHash :: !ByteString
} deriving (Eq, Show)
mkInfo :: BVal -> Maybe Info
, comment = bstrToString =<< comment'
, createdBy = bstrToString =<< createdBy'
, encoding = bstrToString =<< encoding'
+ , infoHash = hash . encode $ (m ! "info")
}
+
mkMetaInfo _ = Nothing
getAnnounceList :: Maybe BVal -> [String]
_ -> "") 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")