@@ -33,6 +33,7 @@ import System.EntropyNix
3333#endif
3434
3535import qualified Data.ByteString as B
36+import Control.Exception (bracket)
3637
3738-- |Get a specific number of bytes of cryptographically
3839-- secure random data using the system-specific facilities.
@@ -41,8 +42,4 @@ import qualified Data.ByteString as B
4142-- Windows. In short, this entropy is considered cryptographically secure
4243-- but not true entropy.
4344getEntropy :: Int -> IO B.ByteString
44−getEntropy n = do
45− h <- openHandle
46− e <- hGetEntropy h n
47− closeHandle h
48− return e
45+getEntropy = bracket openHandle closeHandle . flip hGetEntropy