-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | TLS session manager with limitation, automatic pruning, energy saving
--   and replay resistance and session ticket manager
@package tls-session-manager
@version 0.1.1


-- | The implementation of <a>Network.TLS.SessionManager</a>, exposed for
--   testing. This module may change without notice.
module Network.TLS.SessionManager.Internal

-- | Configuration for session managers.
data Config
Config :: Int -> Int -> Int -> Config

-- | Ticket lifetime in seconds. It should match
--   <a>serverTicketLifetime</a> on a server. A TLS 1.3 session is kept no
--   longer than the lifetime of its ticket.
[ticketLifetime] :: Config -> Int

-- | Pruning delay in seconds. This is set to <a>reaperDelay</a>.
[pruningDelay] :: Config -> Int

-- | The limit size of session data entries.
[dbMaxSize] :: Config -> Int

-- | ticketLifetime: 2 hours (7200 seconds), pruningDelay: 10 minutes (600
--   seconds), dbMaxSize: 1000 entries.
defaultConfig :: Config
toKey :: ByteString -> SessionIDCopy
toValue :: SessionData -> SessionDataCopy
fromValue :: SessionDataCopy -> SessionData
type SessionIDCopy = ShortByteString
newtype SessionDataCopy
SessionDataCopy :: SessionData -> SessionDataCopy
type Sec = Int64
type Value = (SessionDataCopy, IORef Availability)
type Sessions = OrdPSQ SessionIDCopy Sec Value

-- | The sessions, and the keys deleted since the reaper last took them
--   away to prune. While it prunes, the workload left in their place is
--   empty, so a deletion there is kept to be applied to the pruned
--   sessions too.
data DB
DB :: Sessions -> [SessionIDCopy] -> DB
data Item
Add :: SessionIDCopy -> Sec -> Value -> Item
Del :: SessionIDCopy -> Item
data Use
SingleUse :: Use
MultipleUse :: Use
data Availability
Fresh :: Availability
Used :: Availability

-- | Creating an in-memory session manager.
newSessionManager :: Config -> IO SessionManager
cons :: Int -> Item -> DB -> DB
clean :: Int -> DB -> IO (DB -> DB)
establish :: Reaper DB Item -> Sec -> SessionID -> SessionData -> IO ()
resume :: Reaper DB Item -> Use -> SessionID -> IO (Maybe SessionData)
invalidate :: Reaper DB Item -> SessionID -> IO ()
instance GHC.Classes.Eq Network.TLS.SessionManager.Internal.SessionDataCopy
instance GHC.Internal.Show.Show Network.TLS.SessionManager.Internal.SessionDataCopy


-- | In-memory TLS 1.2/1.3 session manager.
--   
--   <ul>
--   <li>Limitation: you can set the maximum size of the session data
--   database.</li>
--   <li>Automatic pruning: old session data over their lifetime are pruned
--   automatically.</li>
--   <li>Energy saving: no dedicate pruning thread is running when the size
--   of session data database is zero.</li>
--   <li>Replay resistance: for 0-RTT early data of TLS 1.3, each session
--   data is used at most once (<tt>sessionResumeOnlyOnce</tt>). Other
--   resumptions may use it again.</li>
--   </ul>
module Network.TLS.SessionManager

-- | Creating an in-memory session manager.
newSessionManager :: Config -> IO SessionManager

-- | Configuration for session managers.
data Config

-- | ticketLifetime: 2 hours (7200 seconds), pruningDelay: 10 minutes (600
--   seconds), dbMaxSize: 1000 entries.
defaultConfig :: Config

-- | Ticket lifetime in seconds. It should match
--   <a>serverTicketLifetime</a> on a server. A TLS 1.3 session is kept no
--   longer than the lifetime of its ticket.
ticketLifetime :: Config -> Int

-- | Pruning delay in seconds. This is set to <a>reaperDelay</a>.
pruningDelay :: Config -> Int

-- | The limit size of session data entries.
dbMaxSize :: Config -> Int


-- | A manager for TLS 1.2/1.3 session ticket.
--   
--   Tracking client hello is not implemented yet. So, if this is used for
--   TLS 1.3 0-RTT, replay attack is possible. If your application data in
--   0-RTT changes the status of server side, use <a>SessionManager</a>
--   instead.
--   
--   A dedicated thread is running repeatedly to replece secret keys. So,
--   energy saving is not achieved.
module Network.TLS.SessionTicket

-- | Creating a session ticket manager.
newSessionTicketManager :: Config -> IO SessionManager
newSessionTicketManager' :: Config -> IO (SessionManager, IO ())

-- | Configuration for session tickets.
data Config

-- | ticketLifetime: 2 hours (7200 seconds), secretKeyInterval: 30 minutes
--   (1800 seconds)
defaultConfig :: Config

-- | Ticket lifetime in seconds. It should match the lifetime the server
--   announces, <a>serverTicketLifetime</a>. As the secret keys are
--   replaced every <a>secretKeyInterval</a>, a ticket is accepted for up
--   to one interval less.
ticketLifetime :: Config -> Int

-- | The interval to replace the secret key in seconds.
secretKeyInterval :: Config -> Int
