{-# LANGUAGE GeneralizedNewtypeDeriving #-} module Network.TLS.RNG ( StateRNG (..), Seed, seedNew, seedToInteger, seedFromInteger, withTLSRNG, newStateRNG, MonadRandom, getRandomBytes, ) where import Crypto.Random newtype StateRNG = StateRNG ChaChaDRG deriving ((forall byteArray. ByteArray byteArray => Int -> StateRNG -> (byteArray, StateRNG)) -> DRG StateRNG forall byteArray. ByteArray byteArray => Int -> StateRNG -> (byteArray, StateRNG) forall gen. (forall byteArray. ByteArray byteArray => Int -> gen -> (byteArray, gen)) -> DRG gen $crandomBytesGenerate :: forall byteArray. ByteArray byteArray => Int -> StateRNG -> (byteArray, StateRNG) randomBytesGenerate :: forall byteArray. ByteArray byteArray => Int -> StateRNG -> (byteArray, StateRNG) DRG) instance Show StateRNG where show :: StateRNG -> String show StateRNG _ = String "rng[..]" withTLSRNG :: StateRNG -> MonadPseudoRandom StateRNG a -> (a, StateRNG) withTLSRNG :: forall a. StateRNG -> MonadPseudoRandom StateRNG a -> (a, StateRNG) withTLSRNG StateRNG rng MonadPseudoRandom StateRNG a f = StateRNG -> MonadPseudoRandom StateRNG a -> (a, StateRNG) forall gen a. DRG gen => gen -> MonadPseudoRandom gen a -> (a, gen) withDRG StateRNG rng MonadPseudoRandom StateRNG a f newStateRNG :: Seed -> StateRNG newStateRNG :: Seed -> StateRNG newStateRNG Seed seed = ChaChaDRG -> StateRNG StateRNG (ChaChaDRG -> StateRNG) -> ChaChaDRG -> StateRNG forall a b. (a -> b) -> a -> b $ Seed -> ChaChaDRG drgNewSeed Seed seed