module Raaz.Entropy( getEntropy ) where
import Control.Monad.IO.Class( MonadIO, liftIO)
import System.IO
import Raaz.Core
getEntropy :: (MonadIO m, LengthUnit l) => l -> Pointer -> m (BYTES Int)
getEntropy :: l -> Pointer -> m (BYTES Int)
getEntropy l
l Pointer
ptr = IO (BYTES Int) -> m (BYTES Int)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (BYTES Int) -> m (BYTES Int))
-> IO (BYTES Int) -> m (BYTES Int)
forall a b. (a -> b) -> a -> b
$ FilePath -> IOMode -> (Handle -> IO (BYTES Int)) -> IO (BYTES Int)
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
withBinaryFile FilePath
"/dev/urandom" IOMode
ReadMode ((Handle -> IO (BYTES Int)) -> IO (BYTES Int))
-> (Handle -> IO (BYTES Int)) -> IO (BYTES Int)
forall a b. (a -> b) -> a -> b
$ \ Handle
hand -> Handle -> Pointer -> l -> IO (BYTES Int)
forall bufSize.
LengthUnit bufSize =>
Handle -> Pointer -> bufSize -> IO (BYTES Int)
hFillBuf Handle
hand Pointer
ptr l
l