-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | A monad for using CryptoRandomGen
--
-- A monad for using CryptoRandomGen
@package monadcryptorandom
@version 0.7.0
-- | Much like the MonadRandom package
-- (Control.Monad.Random), this module provides plumbing for the
-- CryptoRandomGen generators.
module Control.Monad.CryptoRandom
-- | CRandom a is much like the Random class from the
-- System.Random module in the "random" package. The main
-- difference is CRandom builds on "crypto-api"'s CryptoRandomGen,
-- so it allows explicit failure.
--
-- crandomR (low,high) g as typically instantiated will generate
-- a value between [low, high] inclusively, swapping the pair if high
-- < low.
--
-- Provided instances for crandom g generates randoms between
-- the bounds and between +/- 2^256 for Integer.
--
-- The crandomR function has degraded (theoretically unbounded,
-- probabilistically decent) performance the closer your range size (high
-- - low) is to 2^n (from the top).
class CRandom a where crandoms g = case crandom g of { Left _ -> [] Right (a, g') -> a : crandoms g' }
crandom :: (CRandom a, CryptoRandomGen g) => g -> Either GenError (a, g)
crandoms :: (CRandom a, CryptoRandomGen g) => g -> [a]
class CRandomR a where crandomRs r g = case crandomR r g of { Left _ -> [] Right (a, g') -> a : crandomRs r g' }
crandomR :: (CRandomR a, CryptoRandomGen g) => (a, a) -> g -> Either GenError (a, g)
crandomRs :: (CRandomR a, CryptoRandomGen g) => (a, a) -> g -> [a]
-- | MonadCRandom m represents a monad that can produce random
-- values (or fail with a GenError). It is suggested you use the
-- CRandT transformer in your monad stack.
class (ContainsGenError e, MonadError e m) => MonadCRandom e m
getCRandom :: (MonadCRandom e m, CRandom a) => m a
getBytes :: MonadCRandom e m => Int -> m ByteString
getBytesWithEntropy :: MonadCRandom e m => Int -> ByteString -> m ByteString
doReseed :: MonadCRandom e m => ByteString -> m ()
class (ContainsGenError e, MonadError e m) => MonadCRandomR e m
getCRandomR :: (MonadCRandomR e m, CRandomR a) => (a, a) -> m a
class ContainsGenError e
toGenError :: ContainsGenError e => e -> Maybe GenError
fromGenError :: ContainsGenError e => GenError -> e
-- | CRandT is the transformer suggested for MonadCRandom.
newtype CRandT g e m a
CRandT :: StateT g (ExceptT e m) a -> CRandT g e m a
[unCRandT] :: CRandT g e m a -> StateT g (ExceptT e m) a
-- | Simple users of generators can use CRand for quick and easy generation
-- of randoms. See below for a simple use of newGenIO (from
-- "crypto-api"), getCRandom, getBytes, and
-- runCRandom.
--
-- @getRandPair = do int <- getCRandom bytes <- getBytes 100 return
-- (int, bytes)
--
-- func = do g <- newGenIO case runCRand getRandPair g of Right
-- ((int,bytes), g') -> useRandomVals (int,bytes) Left x ->
-- handleGenError x @
type CRand g e = CRandT g e Identity
runCRandT :: ContainsGenError e => CRandT g e m a -> g -> m (Either e (a, g))
evalCRandT :: (ContainsGenError e, Monad m) => CRandT g e m a -> g -> m (Either e a)
runCRand :: (ContainsGenError e) => CRand g e a -> g -> Either e (a, g)
evalCRand :: CRand g GenError a -> g -> Either GenError a
newGenCRand :: (CryptoRandomGen g, MonadCRandom GenError m, Functor m) => m g
liftCRand :: (g -> Either e (a, g)) -> CRand g e a
liftCRandT :: (Monad m) => (g -> Either e (a, g)) -> CRandT g e m a
instance Control.Monad.Fix.MonadFix m => Control.Monad.Fix.MonadFix (Control.Monad.CryptoRandom.CRandT g e m)
instance GHC.Base.Monad m => Control.Monad.Error.Class.MonadError e (Control.Monad.CryptoRandom.CRandT g e m)
instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Control.Monad.CryptoRandom.CRandT g e m)
instance GHC.Base.Monad m => GHC.Base.Monad (Control.Monad.CryptoRandom.CRandT g e m)
instance GHC.Base.Monad m => GHC.Base.Applicative (Control.Monad.CryptoRandom.CRandT g e m)
instance GHC.Base.Functor m => GHC.Base.Functor (Control.Monad.CryptoRandom.CRandT g e m)
instance Control.Monad.CryptoRandom.MonadCRandom e m => Control.Monad.CryptoRandom.MonadCRandom e (Control.Monad.Trans.State.Lazy.StateT s m)
instance Control.Monad.CryptoRandom.MonadCRandom e m => Control.Monad.CryptoRandom.MonadCRandom e (Control.Monad.Trans.State.Strict.StateT s m)
instance (GHC.Base.Monoid w, Control.Monad.CryptoRandom.MonadCRandom e m) => Control.Monad.CryptoRandom.MonadCRandom e (Control.Monad.Trans.Writer.Strict.WriterT w m)
instance (GHC.Base.Monoid w, Control.Monad.CryptoRandom.MonadCRandom e m) => Control.Monad.CryptoRandom.MonadCRandom e (Control.Monad.Trans.Writer.Lazy.WriterT w m)
instance Control.Monad.CryptoRandom.MonadCRandom e m => Control.Monad.CryptoRandom.MonadCRandom e (Control.Monad.Trans.Reader.ReaderT r m)
instance (GHC.Base.Monoid w, Control.Monad.CryptoRandom.MonadCRandom e m) => Control.Monad.CryptoRandom.MonadCRandom e (Control.Monad.Trans.RWS.Strict.RWST r w s m)
instance (GHC.Base.Monoid w, Control.Monad.CryptoRandom.MonadCRandom e m) => Control.Monad.CryptoRandom.MonadCRandom e (Control.Monad.Trans.RWS.Lazy.RWST r w s m)
instance Control.Monad.CryptoRandom.ContainsGenError Crypto.Random.GenError
instance Control.Monad.CryptoRandom.CRandomR GHC.Integer.Type.Integer
instance Control.Monad.CryptoRandom.CRandom GHC.Types.Int
instance Control.Monad.CryptoRandom.CRandomR GHC.Types.Int
instance Control.Monad.CryptoRandom.CRandom GHC.Word.Word8
instance Control.Monad.CryptoRandom.CRandomR GHC.Word.Word8
instance Control.Monad.CryptoRandom.CRandom GHC.Word.Word16
instance Control.Monad.CryptoRandom.CRandomR GHC.Word.Word16
instance Control.Monad.CryptoRandom.CRandom GHC.Word.Word32
instance Control.Monad.CryptoRandom.CRandomR GHC.Word.Word32
instance Control.Monad.CryptoRandom.CRandom GHC.Word.Word64
instance Control.Monad.CryptoRandom.CRandomR GHC.Word.Word64
instance Control.Monad.CryptoRandom.CRandom GHC.Int.Int8
instance Control.Monad.CryptoRandom.CRandomR GHC.Int.Int8
instance Control.Monad.CryptoRandom.CRandom GHC.Int.Int16
instance Control.Monad.CryptoRandom.CRandomR GHC.Int.Int16
instance Control.Monad.CryptoRandom.CRandom GHC.Int.Int32
instance Control.Monad.CryptoRandom.CRandomR GHC.Int.Int32
instance Control.Monad.CryptoRandom.CRandom GHC.Int.Int64
instance Control.Monad.CryptoRandom.CRandomR GHC.Int.Int64
instance Control.Monad.CryptoRandom.CRandom GHC.Types.Bool
instance Control.Monad.Trans.Class.MonadTrans (Control.Monad.CryptoRandom.CRandT g e)
instance Control.Monad.State.Class.MonadState s m => Control.Monad.State.Class.MonadState s (Control.Monad.CryptoRandom.CRandT g e m)
instance Control.Monad.Reader.Class.MonadReader r m => Control.Monad.Reader.Class.MonadReader r (Control.Monad.CryptoRandom.CRandT g e m)
instance Control.Monad.Writer.Class.MonadWriter w m => Control.Monad.Writer.Class.MonadWriter w (Control.Monad.CryptoRandom.CRandT g e m)
instance Control.Monad.Cont.Class.MonadCont m => Control.Monad.Cont.Class.MonadCont (Control.Monad.CryptoRandom.CRandT g e m)
instance (Control.Monad.CryptoRandom.ContainsGenError e, GHC.Base.Monad m, Crypto.Random.CryptoRandomGen g) => Control.Monad.CryptoRandom.MonadCRandom e (Control.Monad.CryptoRandom.CRandT g e m)
instance (Control.Monad.CryptoRandom.ContainsGenError e, GHC.Base.Monad m, Crypto.Random.CryptoRandomGen g) => Control.Monad.CryptoRandom.MonadCRandomR e (Control.Monad.CryptoRandom.CRandT g e m)
instance Control.Monad.CryptoRandom.MonadCRandomR e m => Control.Monad.CryptoRandom.MonadCRandomR e (Control.Monad.Trans.State.Lazy.StateT s m)
instance Control.Monad.CryptoRandom.MonadCRandomR e m => Control.Monad.CryptoRandom.MonadCRandomR e (Control.Monad.Trans.State.Strict.StateT s m)
instance (Control.Monad.CryptoRandom.MonadCRandomR e m, GHC.Base.Monoid w) => Control.Monad.CryptoRandom.MonadCRandomR e (Control.Monad.Trans.Writer.Lazy.WriterT w m)
instance (Control.Monad.CryptoRandom.MonadCRandomR e m, GHC.Base.Monoid w) => Control.Monad.CryptoRandom.MonadCRandomR e (Control.Monad.Trans.Writer.Strict.WriterT w m)
instance Control.Monad.CryptoRandom.MonadCRandomR e m => Control.Monad.CryptoRandom.MonadCRandomR e (Control.Monad.Trans.Reader.ReaderT r m)
instance (Control.Monad.CryptoRandom.MonadCRandomR e m, GHC.Base.Monoid w) => Control.Monad.CryptoRandom.MonadCRandomR e (Control.Monad.Trans.RWS.Lazy.RWST r w s m)
instance (Control.Monad.CryptoRandom.MonadCRandomR e m, GHC.Base.Monoid w) => Control.Monad.CryptoRandom.MonadCRandomR e (Control.Monad.Trans.RWS.Strict.RWST r w s m)