summaryrefslogtreecommitdiff
path: root/dht/src/Codec/AsciiKey256.hs
diff options
context:
space:
mode:
Diffstat (limited to 'dht/src/Codec/AsciiKey256.hs')
-rw-r--r--dht/src/Codec/AsciiKey256.hs7
1 files changed, 4 insertions, 3 deletions
diff --git a/dht/src/Codec/AsciiKey256.hs b/dht/src/Codec/AsciiKey256.hs
index ee17b7c1..1738a368 100644
--- a/dht/src/Codec/AsciiKey256.hs
+++ b/dht/src/Codec/AsciiKey256.hs
@@ -3,6 +3,7 @@ module Codec.AsciiKey256 where
3 3
4import Control.Applicative 4import Control.Applicative
5import Control.Monad 5import Control.Monad
6import Control.Monad.Fail as MF
6import Data.Bits 7import Data.Bits
7import qualified Data.ByteArray as BA 8import qualified Data.ByteArray as BA
8 ;import Data.ByteArray as BA (ByteArrayAccess) 9 ;import Data.ByteArray as BA (ByteArrayAccess)
@@ -112,7 +113,7 @@ readsPrecKey256 publicKey str
112 | otherwise = [] 113 | otherwise = []
113 114
114 115
115parseKey256 :: (Monad m, Alternative m) => String -> m ByteString 116parseKey256 :: (MonadFail m, Alternative m) => String -> m ByteString
116parseKey256 nidstr = do 117parseKey256 nidstr = do
117 let nidbs = C8.pack nidstr 118 let nidbs = C8.pack nidstr
118 (bs,_) = Base16.decode nidbs 119 (bs,_) = Base16.decode nidbs
@@ -121,7 +122,7 @@ parseKey256 nidstr = do
121 43 -> parseToken32 nidstr 122 43 -> parseToken32 nidstr
122 _ -> Left "Wrong size of key." 123 _ -> Left "Wrong size of key."
123 idbs <- (guard (B.length bs == 32) >> return bs) 124 idbs <- (guard (B.length bs == 32) >> return bs)
124 <|> either fail return enid 125 <|> either MF.fail return enid
125 return idbs 126 return idbs
126 127
127readP_key256 :: RP.ReadP ByteString 128readP_key256 :: RP.ReadP ByteString
@@ -131,7 +132,7 @@ readP_key256 = do
131 , fmap (32,) (sequence $ replicate 52 (RP.satisfy zb32digit)) 132 , fmap (32,) (sequence $ replicate 52 (RP.satisfy zb32digit))
132 , fmap (64,) (sequence $ replicate 43 (RP.satisfy b64digit)) 133 , fmap (64,) (sequence $ replicate 43 (RP.satisfy b64digit))
133 ] 134 ]
134 let failure = fail "Bad key." 135 let failure = MF.fail "Bad key."
135 case is64 of 136 case is64 of
136 32 -> case parse32Token32 hexhash of 137 32 -> case parse32Token32 hexhash of
137 Right bs -> return bs 138 Right bs -> return bs