summaryrefslogtreecommitdiff
path: root/src/Data/Torrent
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Torrent')
-rw-r--r--src/Data/Torrent/InfoHash.hs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/Data/Torrent/InfoHash.hs b/src/Data/Torrent/InfoHash.hs
index f730effa..6313948b 100644
--- a/src/Data/Torrent/InfoHash.hs
+++ b/src/Data/Torrent/InfoHash.hs
@@ -127,11 +127,13 @@ instance Convertible Text InfoHash where
127 safeConvert t 127 safeConvert t
128 | hashLen <= 28 = 128 | hashLen <= 28 =
129 case Base64.decode hashStr of 129 case Base64.decode hashStr of
130 Left msg -> convError ("invalid base64 encoding" ++ msg) t 130 Left msg -> convError ("invalid base64 encoding " ++ msg) t
131 Right ihStr -> pure $ InfoHash ihStr 131 Right ihStr -> pure $ InfoHash ihStr
132 132
133 | hashLen == 32 = pure $ InfoHash $ Base32.decode hashStr 133 | hashLen == 32 =
134-- TODO FIX Base32.decode can return 'undefined' 134 case Base32.decode hashStr of
135 Left msg -> convError msg t
136 Right ihStr -> pure $ InfoHash ihStr
135 137
136 | hashLen == 40 = 138 | hashLen == 40 =
137 let (ihStr, inv) = Base16.decode hashStr 139 let (ihStr, inv) = Base16.decode hashStr
@@ -146,9 +148,7 @@ instance Convertible Text InfoHash where
146 148
147-- | Decode from base16\/base32\/base64 encoded string. 149-- | Decode from base16\/base32\/base64 encoded string.
148instance IsString InfoHash where 150instance IsString InfoHash where
149 fromString str = fromMaybe err $ textToInfoHash $ T.pack str 151 fromString = either (error . prettyConvertError) id . safeConvert . T.pack
150 where
151 err = error $ "fromString: invalid infohash string" ++ str
152 152
153-- | Convert to base16 encoded JSON string. 153-- | Convert to base16 encoded JSON string.
154instance ToJSON InfoHash where 154instance ToJSON InfoHash where