diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2016-10-27 22:57:34 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2016-11-19 23:29:43 +0300 |
commit | 4a9f329a6ea9bfa03352ca0d9dd1d556b93bec36 (patch) | |
tree | ec49e853364a61eb4c7c64b5f13b0153d21a4cc1 /src/Sproxy/Application/Cookie.hs | |
download | sproxy2-4a9f329a6ea9bfa03352ca0d9dd1d556b93bec36.tar.gz |
Initial release (1.90.0)1.90.0
Diffstat (limited to 'src/Sproxy/Application/Cookie.hs')
-rw-r--r-- | src/Sproxy/Application/Cookie.hs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Sproxy/Application/Cookie.hs b/src/Sproxy/Application/Cookie.hs new file mode 100644 index 0000000..07cc162 --- /dev/null +++ b/src/Sproxy/Application/Cookie.hs @@ -0,0 +1,44 @@ +module Sproxy.Application.Cookie ( + AuthCookie(..) +, AuthUser(..) +, cookieDecode +, cookieEncode +) where + +import Data.ByteString (ByteString) +import Foreign.C.Types (CTime(..)) +import qualified Data.Serialize as DS + +import qualified Sproxy.Application.State as State + +data AuthUser = AuthUser { + auEmail :: String +, auGivenName :: String +, auFamilyName :: String +} + +data AuthCookie = AuthCookie { + acUser :: AuthUser +, acExpiry :: CTime +} + +instance DS.Serialize AuthCookie where + put c = DS.put (auEmail u, auGivenName u, auFamilyName u, x) + where u = acUser c + x = (\(CTime i) -> i) $ acExpiry c + get = do + (e, n, f, x) <- DS.get + return AuthCookie { + acUser = AuthUser { auEmail = e, auGivenName = n, auFamilyName = f } + , acExpiry = CTime x + } + + +cookieDecode :: ByteString -> ByteString -> Either String AuthCookie +cookieDecode key d = State.decode key d >>= DS.decode + + +cookieEncode :: ByteString -> AuthCookie -> ByteString +cookieEncode key = State.encode key . DS.encode + + |