summaryrefslogtreecommitdiff
path: root/src/Data/Torrent/InfoHash.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-11-28 06:42:10 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-11-28 06:42:10 +0400
commit32027c2d4392fb6964bafe3aaf6d427e5d827d21 (patch)
tree3c58da15d8c7a4b84c9dbe19ac22eb5e6ffed4a8 /src/Data/Torrent/InfoHash.hs
parentfc4ed85a313f93b4fb0c46b500ee12c38e94df68 (diff)
Hide InfoHash constructor
Diffstat (limited to 'src/Data/Torrent/InfoHash.hs')
-rw-r--r--src/Data/Torrent/InfoHash.hs15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/Data/Torrent/InfoHash.hs b/src/Data/Torrent/InfoHash.hs
index a4d6a02e..fd57700a 100644
--- a/src/Data/Torrent/InfoHash.hs
+++ b/src/Data/Torrent/InfoHash.hs
@@ -10,8 +10,7 @@
10{-# LANGUAGE FlexibleInstances #-} 10{-# LANGUAGE FlexibleInstances #-}
11{-# LANGUAGE GeneralizedNewtypeDeriving #-} 11{-# LANGUAGE GeneralizedNewtypeDeriving #-}
12module Data.Torrent.InfoHash 12module Data.Torrent.InfoHash
13 ( -- * Info hash 13 ( InfoHash
14 InfoHash(..)
15 14
16 -- * Parsing 15 -- * Parsing
17 , byteStringToInfoHash 16 , byteStringToInfoHash
@@ -42,6 +41,7 @@ import qualified Data.ByteString.Lazy.Builder as B
42import qualified Data.ByteString.Lazy.Builder.ASCII as B 41import qualified Data.ByteString.Lazy.Builder.ASCII as B
43import Data.Char 42import Data.Char
44import Data.List as L 43import Data.List as L
44import Data.Maybe
45import Data.Hashable as Hashable 45import Data.Hashable as Hashable
46import Data.URLEncoded as URL 46import Data.URLEncoded as URL
47import Data.Serialize 47import Data.Serialize
@@ -85,14 +85,11 @@ instance Read InfoHash where
85 pair (a : b : xs) = (a, b) : pair xs 85 pair (a : b : xs) = (a, b) : pair xs
86 pair _ = [] 86 pair _ = []
87 87
88-- | for base16 (hex) encoded strings 88-- | for base16/base32 encoded strings
89instance IsString InfoHash where 89instance IsString InfoHash where
90 fromString str 90 fromString str = fromMaybe err $ textToInfoHash $ T.pack str
91 | L.length str == 40 91 where
92 , (ihStr, inv) <- Base16.decode $ BC.pack str 92 err = error $ "fromString: invalid infohash string" ++ str
93 = if BS.length inv == 0 then InfoHash ihStr
94 else error "fromString: invalid infohash string"
95 | otherwise = error "fromString: invalid infohash string length"
96 93
97instance Hashable InfoHash where 94instance Hashable InfoHash where
98 hash = Hashable.hash . getInfoHash 95 hash = Hashable.hash . getInfoHash