-- |
-- Module      : Network.TLS.Session
-- License     : BSD-style
-- Maintainer  : Vincent Hanquez <vincent@snarc.org>
-- Stability   : experimental
-- Portability : unknown
--
module Network.TLS.Session
    ( SessionManager(..)
    , noSessionManager
    ) where

import Network.TLS.Types

-- | A session manager
data SessionManager = SessionManager
    { -- | used on server side to decide whether to resume a client session.
      SessionManager -> SessionID -> IO (Maybe SessionData)
sessionResume         :: SessionID -> IO (Maybe SessionData)
      -- | used on server side to decide whether to resume a client session for TLS 1.3 0RTT. For a given 'SessionID', the implementation must return its 'SessionData' only once and must not return the same 'SessionData' after the call.
    , SessionManager -> SessionID -> IO (Maybe SessionData)
sessionResumeOnlyOnce :: SessionID -> IO (Maybe SessionData)
      -- | used when a session is established.
    , SessionManager -> SessionID -> SessionData -> IO ()
sessionEstablish      :: SessionID -> SessionData -> IO ()
      -- | used when a session is invalidated.
    , SessionManager -> SessionID -> IO ()
sessionInvalidate     :: SessionID -> IO ()
    }

-- | The session manager to do nothing.
noSessionManager :: SessionManager
noSessionManager :: SessionManager
noSessionManager = SessionManager :: (SessionID -> IO (Maybe SessionData))
-> (SessionID -> IO (Maybe SessionData))
-> (SessionID -> SessionData -> IO ())
-> (SessionID -> IO ())
-> SessionManager
SessionManager
    { sessionResume :: SessionID -> IO (Maybe SessionData)
sessionResume         = \SessionID
_   -> Maybe SessionData -> IO (Maybe SessionData)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe SessionData
forall a. Maybe a
Nothing
    , sessionResumeOnlyOnce :: SessionID -> IO (Maybe SessionData)
sessionResumeOnlyOnce = \SessionID
_   -> Maybe SessionData -> IO (Maybe SessionData)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe SessionData
forall a. Maybe a
Nothing
    , sessionEstablish :: SessionID -> SessionData -> IO ()
sessionEstablish      = \SessionID
_ SessionData
_ -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    , sessionInvalidate :: SessionID -> IO ()
sessionInvalidate     = \SessionID
_   -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    }