| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Crypto.Token
Description
Encrypted tokens/tickets to keep state in the client side.
Synopsis
- data Config
- defaultConfig :: Config
- interval :: Config -> Int
- tokenLifetime :: Config -> Int
- threadName :: Config -> String
- data TokenManager
- spawnTokenManager :: Config -> IO TokenManager
- killTokenManager :: TokenManager -> IO ()
- encryptToken :: TokenManager -> ByteString -> IO ByteString
- decryptToken :: TokenManager -> ByteString -> IO (Maybe ByteString)
Configuration
Configuration for token manager.
defaultConfig :: Config Source #
Default configuration to update secrets in 30 minutes (1,800 seconds) and token lifetime is 2 hours (7,200 seconds)
>>>defaultConfigConfig {interval = 1800, tokenLifetime = 7200, threadName = "Crypto token manager"}
interval :: Config -> Int Source #
The interval to generate a new secret and remove the oldest one in seconds.
tokenLifetime :: Config -> Int Source #
The token lifetime in seconds, that is, tokens can be decrypted in this period. It is cut short if it spans more than 65535 intervals.
threadName :: Config -> String Source #
The label of the thread used without the timer manager.
Token manager
data TokenManager Source #
The abstract data type for token manager.
spawnTokenManager :: Config -> IO TokenManager Source #
Spawning a token manager. Secrets are rotated every interval by a
timer of the RTS, with no thread of its own, also when no token is
made. The timer ends with killTokenManager, or once the manager is
garbage-collected. Without the timer manager of the threaded RTS on
a POSIX system, a thread does the same.
This throws an IOError if interval is not positive.
killTokenManager :: TokenManager -> IO () Source #
Killing a token manager: its rotation stops and the secrets made so far are forgotten.
Encryption and decryption
encryptToken :: TokenManager -> ByteString -> IO ByteString Source #
Encrypting a target value to get a token.
decryptToken :: TokenManager -> ByteString -> IO (Maybe ByteString) Source #
Decrypting a token to get a target value.