add an helper to use the compression context easily

This commit is contained in:
Vincent Hanquez 2011-08-12 18:33:28 +01:00
parent d4ca9e0d9d
commit 84ace35a7e

View file

@ -21,6 +21,7 @@ module Network.TLS.State
, newTLSState
, genTLSRandom
, withTLSRNG
, withCompression
, assert -- FIXME move somewhere else (Internal.hs ?)
, updateStatusHs
, updateStatusCC
@ -175,6 +176,13 @@ withTLSRNG (StateRNG rng) f = case f rng of
Left err -> Left err
Right (a, rng') -> Right (a, StateRNG rng')
withCompression :: (Compression -> (Compression, a)) -> TLSSt a
withCompression f = do
compression <- stCompression <$> get
let (nc, a) = f compression
modify (\st -> st { stCompression = nc })
return a
genTLSRandom :: (MonadState TLSState m, MonadError TLSError m) => Int -> m Bytes
genTLSRandom n = do
st <- get