@@ -22,13 +22,9 @@ module System.Entropy
2222 , closeHandle
2323 ) where
2424
25−#ifndef XEN
2625import Control.Monad (liftM, when)
2726import System.IO.Error (mkIOError, eofErrorType, ioeSetErrorString)
2827import Foreign (allocaBytes)
29−#else
30−import Control.Monad (when)
31−#endif
3228import Data.ByteString as B
3329
3430#if defined(isWindows)
@@ -127,11 +123,11 @@ getEntropy n = do
127123 if b then hGetEntropy UseRdRand n
128124 else do
129125#endif
130− h <- cryptAcquireCtx
131− bs <- cryptGenRandom h n
132− let !bs' = bs
133− cryptReleaseCtx h
134− return bs'
126+ h <- cryptAcquireCtx
127+ bs <- cryptGenRandom h n
128+ let !bs' = bs
129+ cryptReleaseCtx h
130+ return bs'
135131
136132-- |Open a handle from which random data can be read
137133openHandle :: IO CryptHandle
@@ -141,16 +137,16 @@ openHandle = do
141137 if b then return UseRdRand
142138 else do
143139#endif
144− liftM CH cryptAcquireCtx
140+ liftM CH cryptAcquireCtx
145141
146142-- |Close the `CryptHandle`
147143closeHandle (CH h) = cryptReleaseCtx h
148144
149145-- |Read from `CryptHandle`
150146hGetEntropy :: CryptHandle -> Int -> IO B.ByteString
151−hGetEntropy (CH h) = cryptGenRandom h
147+hGetEntropy (CH h) n = cryptGenRandom h n
152148#ifdef HAVE_RDRAND
153−hGetEntropy UseRdRand =
149+hGetEntropy UseRdRand n =
154150 B.create n $ \ptr -> do
155151 r <- c_get_rand_bytes (castPtr ptr) (fromIntegral n)
156152 when (r /= 0)