git.iko.soy/typeable/entropy
on main help sign in
Merge pull request #28 from redneb/use-bracket

Use bracket to ensure async exception safety

commit986dd9916653849933364bb41bb9bd0912c1e6d7 authorThomas M. DuBuisson <thomas.dubuisson@gmail.com> dateFri 25 Mar 2016, 07:59 (11 years ago) parent5422644f33ccef
1 file changed+2−5
System/Entropy.hs+2−5
System/Entropy.hs+2−5
@@ -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