diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-28 06:42:10 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-28 06:42:10 +0400 |
commit | 32027c2d4392fb6964bafe3aaf6d427e5d827d21 (patch) | |
tree | 3c58da15d8c7a4b84c9dbe19ac22eb5e6ffed4a8 /src/Data/Torrent/InfoHash.hs | |
parent | fc4ed85a313f93b4fb0c46b500ee12c38e94df68 (diff) |
Hide InfoHash constructor
Diffstat (limited to 'src/Data/Torrent/InfoHash.hs')
-rw-r--r-- | src/Data/Torrent/InfoHash.hs | 15 |
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 #-} |
12 | module Data.Torrent.InfoHash | 12 | module 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 | |||
42 | import qualified Data.ByteString.Lazy.Builder.ASCII as B | 41 | import qualified Data.ByteString.Lazy.Builder.ASCII as B |
43 | import Data.Char | 42 | import Data.Char |
44 | import Data.List as L | 43 | import Data.List as L |
44 | import Data.Maybe | ||
45 | import Data.Hashable as Hashable | 45 | import Data.Hashable as Hashable |
46 | import Data.URLEncoded as URL | 46 | import Data.URLEncoded as URL |
47 | import Data.Serialize | 47 | import 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 |
89 | instance IsString InfoHash where | 89 | instance 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 | ||
97 | instance Hashable InfoHash where | 94 | instance Hashable InfoHash where |
98 | hash = Hashable.hash . getInfoHash | 95 | hash = Hashable.hash . getInfoHash |