aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Crypto
diff options
context:
space:
mode:
authorJulien Tanguy <julien.tanguy@jhome.fr>2015-04-14 17:43:52 +0200
committerJulien Tanguy <julien.tanguy@jhome.fr>2015-04-14 17:43:52 +0200
commit30c4b9252064ed044adf1776ff9501841c4de2fe (patch)
treec223ec6fccba479a4782a6801024fd6e4baf7b2c /src/Crypto
parenta20c77f85bcbc74b70c108f440435c70b29ab822 (diff)
downloadhmacaroons-30c4b9252064ed044adf1776ff9501841c4de2fe.tar.gz
hmacaroons-30c4b9252064ed044adf1776ff9501841c4de2fe.tar.zst
hmacaroons-30c4b9252064ed044adf1776ff9501841c4de2fe.zip
Change Eq instances
Diffstat (limited to 'src/Crypto')
-rw-r--r--src/Crypto/Macaroon/Internal.hs24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/Crypto/Macaroon/Internal.hs b/src/Crypto/Macaroon/Internal.hs
index 810591c..ebd25cb 100644
--- a/src/Crypto/Macaroon/Internal.hs
+++ b/src/Crypto/Macaroon/Internal.hs
@@ -42,7 +42,15 @@ data Macaroon = MkMacaroon { location :: Location
42 -- ^ List of caveats 42 -- ^ List of caveats
43 , signature :: Sig 43 , signature :: Sig
44 -- ^ Macaroon HMAC signature 44 -- ^ Macaroon HMAC signature
45 } deriving (Eq) 45 }
46
47instance Eq Macaroon where
48 (MkMacaroon l1 i1 c1 s1) == (MkMacaroon l2 i2 c2 s2) =
49 (l1 `constEqBytes` l2) &&!
50 (i1 `constEqBytes` i2) &&!
51 (c1 == c2) &&!
52 (s1 `constEqBytes` s2)
53
46 54
47-- | show instance conforming to the @inspect@ "specification" 55-- | show instance conforming to the @inspect@ "specification"
48instance Show Macaroon where 56instance Show Macaroon where
@@ -66,8 +74,13 @@ data Caveat = MkCaveat { cid :: Key
66 -- ^ Caveat verification key identifier 74 -- ^ Caveat verification key identifier
67 , cl :: Location 75 , cl :: Location
68 -- ^ Caveat target location 76 -- ^ Caveat target location
77 }
69 78
70 } deriving (Eq) 79instance Eq Caveat where
80 (MkCaveat c1 v1 l1) == (MkCaveat c2 v2 l2) =
81 (c1 `constEqBytes` c2) &&!
82 (v1 `constEqBytes` v2) &&!
83 (l1 `constEqBytes` l2)
71 84
72-- | show instance conforming to the @inspect@ "specification" 85-- | show instance conforming to the @inspect@ "specification"
73instance Show Caveat where 86instance Show Caveat where
@@ -95,3 +108,10 @@ addCaveat loc cid vid m = m { caveats = cavs ++ [cav'], signature = sig}
95 cav' = MkCaveat cid vid loc 108 cav' = MkCaveat cid vid loc
96 sig = toBytes (hmac (signature m) (BS.append vid cid) :: HMAC SHA256) 109 sig = toBytes (hmac (signature m) (BS.append vid cid) :: HMAC SHA256)
97 110
111-- | Utility non-short circuiting '&&' function.
112(&&!) :: Bool -> Bool -> Bool
113True &&! True = True
114True &&! False = False
115False &&! True = False
116False &&! False = False
117