summaryrefslogtreecommitdiff
path: root/src/Data/Torrent/Magnet.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Torrent/Magnet.hs')
-rw-r--r--src/Data/Torrent/Magnet.hs15
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
28import Control.Applicative 28import Control.Applicative
29import Control.Monad 29import Control.Monad
30import Data.ByteString as BS
31import Data.ByteString.Base16 as Base16
32import Data.ByteString.Base32 as Base32
33import Data.Map as M 30import Data.Map as M
34import Data.Maybe 31import Data.Maybe
35import Data.List as L 32import Data.List as L
36import Data.URLEncoded as URL 33import Data.URLEncoded as URL
37import Data.String 34import Data.String
38import Data.Text as T 35import Data.Text as T
39import Data.Text.Encoding as T
40import Network.URI 36import Network.URI
41import Text.Read 37import Text.Read
42 38
@@ -90,16 +86,7 @@ renderURN URN {..}
90urnToInfoHash :: URN -> Maybe InfoHash 86urnToInfoHash :: URN -> Maybe InfoHash
91urnToInfoHash (URN {..}) 87urnToInfoHash (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
104infoHashToURN :: InfoHash -> URN 91infoHashToURN :: InfoHash -> URN
105infoHashToURN = URN btih . T.pack . show 92infoHashToURN = URN btih . T.pack . show