-- 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.4 -- | 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 crandom :: (CRandom a, CryptoRandomGen g) => g -> Either GenError (a, g) crandoms :: (CRandom a, CryptoRandomGen g) => g -> [a] class CRandomR a 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 -- | A superclass including MonadCRandom and MonadCRandomR class -- (MonadCRandom e m, MonadCRandomR e m) => MonadCRand e m instance -- (MonadCRandom e m, MonadCRandomR e m) => MonadCRand e m class ContainsGenError e toGenError :: ContainsGenError e => e -> Maybe GenError fromGenError :: ContainsGenError e => GenError -> e -- | CRandT is the transformer suggested for MonadCRandom. data CRandT g 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 :: CRand g GenError a -> g -> Either GenError (a, g) evalCRand :: CRand g GenError a -> g -> Either GenError a instance (Monad m, Error e) => MonadError e (CRandT g e m) instance (Monad m, Error e) => Monad (CRandT g e m) instance (MonadIO m, Error e) => MonadIO (CRandT g e m) instance Functor m => Functor (CRandT g e m) instance (MonadFix m, Error e) => MonadFix (CRandT g e m) instance Error GenError instance (ContainsGenError e, Error e, Monad m, CryptoRandomGen g) => MonadCRandomR e (CRandT g e m) instance (ContainsGenError e, Error e, Monad m, CryptoRandomGen g) => MonadCRandom e (CRandT g e m) instance Error e => MonadTrans (CRandT g e) instance (Functor m, Monad m, Error e) => Applicative (CRandT g e m) instance CRandomR Int64 instance CRandom Int64 instance CRandomR Int32 instance CRandom Int32 instance CRandomR Int16 instance CRandom Int16 instance CRandomR Int8 instance CRandom Int8 instance CRandomR Word64 instance CRandom Word64 instance CRandomR Word32 instance CRandom Word32 instance CRandomR Word16 instance CRandom Word16 instance CRandomR Word8 instance CRandom Word8 instance CRandomR Int instance CRandom Int instance CRandomR Integer instance ContainsGenError GenError