aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Crypto
diff options
context:
space:
mode:
Diffstat (limited to 'src/Crypto')
-rw-r--r--src/Crypto/Macaroon/Verifier.hs15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/Crypto/Macaroon/Verifier.hs b/src/Crypto/Macaroon/Verifier.hs
index cb64c9d..012d156 100644
--- a/src/Crypto/Macaroon/Verifier.hs
+++ b/src/Crypto/Macaroon/Verifier.hs
@@ -16,6 +16,7 @@ module Crypto.Macaroon.Verifier (
16 Verified(..) 16 Verified(..)
17 , verifySig 17 , verifySig
18 , verifyExact 18 , verifyExact
19 , verifyFun
19 , verifyCavs 20 , verifyCavs
20 -- , module Data.Attoparsec.ByteString 21 -- , module Data.Attoparsec.ByteString
21 , module Data.Attoparsec.ByteString.Char8 22 , module Data.Attoparsec.ByteString.Char8
@@ -55,10 +56,13 @@ verifySig k m = bool Failed Ok $
55verifyCavs :: [Caveat -> Maybe Verified] -> Macaroon -> Verified 56verifyCavs :: [Caveat -> Maybe Verified] -> Macaroon -> Verified
56verifyCavs verifiers m = mconcat $ map (\c -> mconcat . catMaybes $ map ($ c) verifiers) (caveats m) 57verifyCavs verifiers m = mconcat $ map (\c -> mconcat . catMaybes $ map ($ c) verifiers) (caveats m)
57 58
58verifyExact :: (Show a, Eq a) => Key -> a -> Parser a -> Caveat -> Maybe Verified 59verifyExact :: (Eq a) => Key -> a -> Parser a -> Caveat -> Maybe Verified
59verifyExact key expected parser cav = if key `BS.isPrefixOf` cid cav then 60verifyExact k expected = verifyFun k (expected ==)
61
62verifyFun :: Key -> (a -> Bool) -> Parser a -> Caveat -> Maybe Verified
63verifyFun key f parser cav = if key `BS.isPrefixOf` cid cav then
60 case parseOnly kvparser (cid cav) of 64 case parseOnly kvparser (cid cav) of
61 Right v -> verify <$> Just v 65 Right v -> (bool Failed Ok . f) <$> Just v
62 Left _ -> Just Failed 66 Left _ -> Just Failed
63 else Nothing 67 else Nothing
64 where 68 where
@@ -67,7 +71,4 @@ verifyExact key expected parser cav = if key `BS.isPrefixOf` cid cav then
67 skipSpace 71 skipSpace
68 string "=" 72 string "="
69 skipSpace 73 skipSpace
70 parser 74 parser <* endOfInput
71
72 -- *> skipSpace *> string "=" *> skipSpace *> parser <* endOfInput
73 verify a = bool Failed Ok (a == expected)