    -- |
    -- Module      : Crypto.Random.Entropy
    -- License     : BSD-style
    -- Maintainer  : Vincent Hanquez <vincent@snarc.org>
    -- Stability   : experimental
    -- Portability : Good
    module Crypto.Random.Entropy (
        getEntropy,
    ) where

    import Crypto.Internal.ByteArray (ByteArray)
    import qualified Crypto.Internal.ByteArray as B
    import Data.Maybe (catMaybes)

    import Crypto.Random.Entropy.Unsafe

    -- | Get some entropy from the system source of entropy
    getEntropy :: ByteArray byteArray => Int -> IO byteArray
    getEntropy :: forall byteArray. ByteArray byteArray => Int -> IO byteArray
    getEntropy Int
    n = do
        backends <- [Maybe EntropyBackend] -> [EntropyBackend]
    forall a. [Maybe a] -> [a]
    catMaybes ([Maybe EntropyBackend] -> [EntropyBackend])
    -> IO [Maybe EntropyBackend] -> IO [EntropyBackend]
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    `fmap` [IO (Maybe EntropyBackend)] -> IO [Maybe EntropyBackend]
    forall (t :: * -> *) (m :: * -> *) a.
    (Traversable t, Monad m) =>
    t (m a) -> m (t a)
    forall (m :: * -> *) a. Monad m => [m a] -> m [a]
    sequence [IO (Maybe EntropyBackend)]
    supportedBackends
        B.alloc n (replenish n backends)