diff options
author | Julien Tanguy <julien.tanguy@jhome.fr> | 2015-04-14 17:43:52 +0200 |
---|---|---|
committer | Julien Tanguy <julien.tanguy@jhome.fr> | 2015-04-14 17:43:52 +0200 |
commit | 30c4b9252064ed044adf1776ff9501841c4de2fe (patch) | |
tree | c223ec6fccba479a4782a6801024fd6e4baf7b2c | |
parent | a20c77f85bcbc74b70c108f440435c70b29ab822 (diff) | |
download | hmacaroons-30c4b9252064ed044adf1776ff9501841c4de2fe.tar.gz hmacaroons-30c4b9252064ed044adf1776ff9501841c4de2fe.tar.zst hmacaroons-30c4b9252064ed044adf1776ff9501841c4de2fe.zip |
Change Eq instances
-rw-r--r-- | src/Crypto/Macaroon/Internal.hs | 24 |
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 | |||
47 | instance 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" |
48 | instance Show Macaroon where | 56 | instance 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) | 79 | instance 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" |
73 | instance Show Caveat where | 86 | instance 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 | ||
113 | True &&! True = True | ||
114 | True &&! False = False | ||
115 | False &&! True = False | ||
116 | False &&! False = False | ||
117 | |||