aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Crypto
diff options
context:
space:
mode:
Diffstat (limited to 'src/Crypto')
-rw-r--r--src/Crypto/Macaroon.hs6
-rw-r--r--src/Crypto/Macaroon/Internal.hs10
2 files changed, 14 insertions, 2 deletions
diff --git a/src/Crypto/Macaroon.hs b/src/Crypto/Macaroon.hs
index 42e4a07..07043f7 100644
--- a/src/Crypto/Macaroon.hs
+++ b/src/Crypto/Macaroon.hs
@@ -25,6 +25,7 @@ module Crypto.Macaroon (
25 , Caveat 25 , Caveat
26 , Key 26 , Key
27 , Location 27 , Location
28 , Sig
28 -- * Accessing functions 29 -- * Accessing functions
29 -- ** Macaroons 30 -- ** Macaroons
30 , location 31 , location
@@ -65,18 +66,23 @@ create secret ident loc = MkMacaroon loc ident [] (toBytes (hmac derivedKey iden
65 where 66 where
66 derivedKey = toBytes (hmac "macaroons-key-generator" secret :: HMAC SHA256) 67 derivedKey = toBytes (hmac "macaroons-key-generator" secret :: HMAC SHA256)
67 68
69-- | Caveat target location
68caveatLoc :: Caveat -> Location 70caveatLoc :: Caveat -> Location
69caveatLoc = cl 71caveatLoc = cl
70 72
73-- | Caveat identifier
71caveatId :: Caveat -> Key 74caveatId :: Caveat -> Key
72caveatId = cid 75caveatId = cid
73 76
77-- | Caveat verification identifier
74caveatVId :: Caveat -> Key 78caveatVId :: Caveat -> Key
75caveatVId = vid 79caveatVId = vid
76 80
81-- | Inspect a macaroon's contents. For debugging purposes.
77inspect :: Macaroon -> String 82inspect :: Macaroon -> String
78inspect = show 83inspect = show
79 84
85-- | Serialize a macaroon in an URL-safe Base64 encoding
80serialize :: Macaroon -> BS.ByteString 86serialize :: Macaroon -> BS.ByteString
81serialize m = B8.filter (/= '=') . B64.encode $ packets 87serialize m = B8.filter (/= '=') . B64.encode $ packets
82 where 88 where
diff --git a/src/Crypto/Macaroon/Internal.hs b/src/Crypto/Macaroon/Internal.hs
index 82ce0b4..810591c 100644
--- a/src/Crypto/Macaroon/Internal.hs
+++ b/src/Crypto/Macaroon/Internal.hs
@@ -27,9 +27,10 @@ import Data.List
27-- |Type alias for Macaroons and Caveat keys and identifiers 27-- |Type alias for Macaroons and Caveat keys and identifiers
28type Key = BS.ByteString 28type Key = BS.ByteString
29 29
30-- |Type alias For Macaroons and Caveat locations 30-- |Type alias for Macaroons and Caveat locations
31type Location = BS.ByteString 31type Location = BS.ByteString
32 32
33-- |Type alias for Macaroons signatures
33type Sig = BS.ByteString 34type Sig = BS.ByteString
34 35
35-- | Main structure of a macaroon 36-- | Main structure of a macaroon
@@ -43,6 +44,7 @@ data Macaroon = MkMacaroon { location :: Location
43 -- ^ Macaroon HMAC signature 44 -- ^ Macaroon HMAC signature
44 } deriving (Eq) 45 } deriving (Eq)
45 46
47-- | show instance conforming to the @inspect@ "specification"
46instance Show Macaroon where 48instance Show Macaroon where
47 -- We use intercalate because unlines would add a trailing newline 49 -- We use intercalate because unlines would add a trailing newline
48 show (MkMacaroon l i c s) = intercalate "\n" [ 50 show (MkMacaroon l i c s) = intercalate "\n" [
@@ -52,6 +54,7 @@ instance Show Macaroon where
52 , "signature " ++ B8.unpack (hex s) 54 , "signature " ++ B8.unpack (hex s)
53 ] 55 ]
54 56
57-- | NFData instance for use in the benchmark
55instance NFData Macaroon where 58instance NFData Macaroon where
56 rnf (MkMacaroon loc ident cavs sig) = rnf loc `seq` rnf ident `seq` rnf cavs `seq` rnf sig 59 rnf (MkMacaroon loc ident cavs sig) = rnf loc `seq` rnf ident `seq` rnf cavs `seq` rnf sig
57 60
@@ -66,6 +69,7 @@ data Caveat = MkCaveat { cid :: Key
66 69
67 } deriving (Eq) 70 } deriving (Eq)
68 71
72-- | show instance conforming to the @inspect@ "specification"
69instance Show Caveat where 73instance Show Caveat where
70 show (MkCaveat c v l) | v == BS.empty = "cid " ++ B8.unpack c 74 show (MkCaveat c v l) | v == BS.empty = "cid " ++ B8.unpack c
71 | otherwise = unlines [ "cid " ++ B8.unpack c 75 | otherwise = unlines [ "cid " ++ B8.unpack c
@@ -74,10 +78,12 @@ instance Show Caveat where
74 ] 78 ]
75 79
76 80
81-- | NFData instance for use in the benchmark
77instance NFData Caveat where 82instance NFData Caveat where
78 rnf (MkCaveat cid vid cl) = rnf cid `seq` rnf vid `seq` rnf cl 83 rnf (MkCaveat cid vid cl) = rnf cid `seq` rnf vid `seq` rnf cl
79 84
80 85-- | Primitive to add a First or Third party caveat to a macaroon
86-- For internal use only
81addCaveat :: Location 87addCaveat :: Location
82 -> Key 88 -> Key
83 -> Key 89 -> Key