diff options
Diffstat (limited to 'src/Data/Torrent/Magnet.hs')
-rw-r--r-- | src/Data/Torrent/Magnet.hs | 15 |
1 files changed, 1 insertions, 14 deletions
diff --git a/src/Data/Torrent/Magnet.hs b/src/Data/Torrent/Magnet.hs index df928b66..34a7bbc5 100644 --- a/src/Data/Torrent/Magnet.hs +++ b/src/Data/Torrent/Magnet.hs | |||
@@ -27,16 +27,12 @@ module Data.Torrent.Magnet | |||
27 | 27 | ||
28 | import Control.Applicative | 28 | import Control.Applicative |
29 | import Control.Monad | 29 | import Control.Monad |
30 | import Data.ByteString as BS | ||
31 | import Data.ByteString.Base16 as Base16 | ||
32 | import Data.ByteString.Base32 as Base32 | ||
33 | import Data.Map as M | 30 | import Data.Map as M |
34 | import Data.Maybe | 31 | import Data.Maybe |
35 | import Data.List as L | 32 | import Data.List as L |
36 | import Data.URLEncoded as URL | 33 | import Data.URLEncoded as URL |
37 | import Data.String | 34 | import Data.String |
38 | import Data.Text as T | 35 | import Data.Text as T |
39 | import Data.Text.Encoding as T | ||
40 | import Network.URI | 36 | import Network.URI |
41 | import Text.Read | 37 | import Text.Read |
42 | 38 | ||
@@ -90,16 +86,7 @@ renderURN URN {..} | |||
90 | urnToInfoHash :: URN -> Maybe InfoHash | 86 | urnToInfoHash :: URN -> Maybe InfoHash |
91 | urnToInfoHash (URN {..}) | 87 | urnToInfoHash (URN {..}) |
92 | | urnNamespace /= btih = Nothing | 88 | | urnNamespace /= btih = Nothing |
93 | | hashLen == 20 = Just $ InfoHash hashStr | 89 | | otherwise = textToInfoHash urnString |
94 | | hashLen == 32 = Just $ InfoHash $ Base32.decode hashStr | ||
95 | | hashLen == 40 = let (ihStr, inv) = Base16.decode hashStr | ||
96 | in if BS.length inv == 0 | ||
97 | then Just $ InfoHash ihStr | ||
98 | else Nothing | ||
99 | | otherwise = Nothing | ||
100 | where | ||
101 | hashLen = BS.length hashStr | ||
102 | hashStr = T.encodeUtf8 urnString | ||
103 | 90 | ||
104 | infoHashToURN :: InfoHash -> URN | 91 | infoHashToURN :: InfoHash -> URN |
105 | infoHashToURN = URN btih . T.pack . show | 92 | infoHashToURN = URN btih . T.pack . show |