summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Data/Torrent.hs4
-rw-r--r--src/Data/Torrent/InfoHash.hs10
-rw-r--r--src/Network/BitTorrent/Tracker/Message.hs3
3 files changed, 7 insertions, 10 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index d6227b6f..b3ac7586 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -78,10 +78,10 @@ import Data.ByteString as BS
78import qualified Data.ByteString.Char8 as BC (pack, unpack) 78import qualified Data.ByteString.Char8 as BC (pack, unpack)
79import qualified Data.ByteString.Lazy as BL 79import qualified Data.ByteString.Lazy as BL
80import Data.Char as Char 80import Data.Char as Char
81import Data.Convertible
81import Data.Default 82import Data.Default
82import Data.Hashable as Hashable 83import Data.Hashable as Hashable
83import qualified Data.List as L 84import qualified Data.List as L
84import Data.Maybe
85import Data.Text as T 85import Data.Text as T
86import Data.Time 86import Data.Time
87import Data.Time.Clock.POSIX 87import Data.Time.Clock.POSIX
@@ -155,7 +155,7 @@ putPrivate True = \ cont -> "private" .=! True .: cont
155 155
156-- | Hash lazy bytestring using SHA1 algorithm. 156-- | Hash lazy bytestring using SHA1 algorithm.
157hashLazyIH :: BL.ByteString -> InfoHash 157hashLazyIH :: BL.ByteString -> InfoHash
158hashLazyIH = fromMaybe (error msg) . byteStringToInfoHash . C.hashlazy 158hashLazyIH = either (const (error msg)) id . safeConvert . C.hashlazy
159 where 159 where
160 msg = "Infohash.hash: impossible: SHA1 is always 20 bytes long" 160 msg = "Infohash.hash: impossible: SHA1 is always 20 bytes long"
161 161
diff --git a/src/Data/Torrent/InfoHash.hs b/src/Data/Torrent/InfoHash.hs
index 7442c61c..08cee3c9 100644
--- a/src/Data/Torrent/InfoHash.hs
+++ b/src/Data/Torrent/InfoHash.hs
@@ -15,7 +15,6 @@ module Data.Torrent.InfoHash
15 ( InfoHash 15 ( InfoHash
16 16
17 -- * Parsing 17 -- * Parsing
18 , byteStringToInfoHash
19 , textToInfoHash 18 , textToInfoHash
20 19
21 -- * Rendering 20 -- * Rendering
@@ -163,12 +162,9 @@ instance FromJSON InfoHash where
163ignoreErrorMsg :: Either a b -> Maybe b 162ignoreErrorMsg :: Either a b -> Maybe b
164ignoreErrorMsg = either (const Nothing) Just 163ignoreErrorMsg = either (const Nothing) Just
165 164
166-- | TODO remove from API 165-- | Tries both base16 and base32 while decoding info hash.
167byteStringToInfoHash :: BS.ByteString -> Maybe InfoHash 166--
168byteStringToInfoHash = ignoreErrorMsg . safeConvert 167-- Use 'safeConvert' for detailed error messages.
169
170-- | Tries both base16 and base32 while decoding info hash. To Use
171-- 'safeConvert' to find out
172-- 168--
173textToInfoHash :: Text -> Maybe InfoHash 169textToInfoHash :: Text -> Maybe InfoHash
174textToInfoHash = ignoreErrorMsg . safeConvert 170textToInfoHash = ignoreErrorMsg . safeConvert
diff --git a/src/Network/BitTorrent/Tracker/Message.hs b/src/Network/BitTorrent/Tracker/Message.hs
index e5d8b25a..3437dcf3 100644
--- a/src/Network/BitTorrent/Tracker/Message.hs
+++ b/src/Network/BitTorrent/Tracker/Message.hs
@@ -55,6 +55,7 @@ import Data.BEncode.BDict as BE
55import Data.ByteString as BS 55import Data.ByteString as BS
56import Data.ByteString.Char8 as BC 56import Data.ByteString.Char8 as BC
57import Data.Char as Char 57import Data.Char as Char
58import Data.Convertible
58import Data.List as L 59import Data.List as L
59import Data.Map as M 60import Data.Map as M
60import Data.Maybe 61import Data.Maybe
@@ -265,7 +266,7 @@ class FromParam a where
265 fromParam :: BS.ByteString -> Maybe a 266 fromParam :: BS.ByteString -> Maybe a
266 267
267instance FromParam InfoHash where 268instance FromParam InfoHash where
268 fromParam = byteStringToInfoHash 269 fromParam = either (const Nothing) pure . safeConvert
269 270
270instance FromParam PeerId where 271instance FromParam PeerId where
271 fromParam = byteStringToPeerId 272 fromParam = byteStringToPeerId