diff options
Diffstat (limited to 'src/Crypto')
-rw-r--r-- | src/Crypto/Macaroon/Verifier.hs | 15 |
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 $ | |||
55 | verifyCavs :: [Caveat -> Maybe Verified] -> Macaroon -> Verified | 56 | verifyCavs :: [Caveat -> Maybe Verified] -> Macaroon -> Verified |
56 | verifyCavs verifiers m = mconcat $ map (\c -> mconcat . catMaybes $ map ($ c) verifiers) (caveats m) | 57 | verifyCavs verifiers m = mconcat $ map (\c -> mconcat . catMaybes $ map ($ c) verifiers) (caveats m) |
57 | 58 | ||
58 | verifyExact :: (Show a, Eq a) => Key -> a -> Parser a -> Caveat -> Maybe Verified | 59 | verifyExact :: (Eq a) => Key -> a -> Parser a -> Caveat -> Maybe Verified |
59 | verifyExact key expected parser cav = if key `BS.isPrefixOf` cid cav then | 60 | verifyExact k expected = verifyFun k (expected ==) |
61 | |||
62 | verifyFun :: Key -> (a -> Bool) -> Parser a -> Caveat -> Maybe Verified | ||
63 | verifyFun 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) | ||