git.iko.soy/typeable/entropy
on main help sign in
Merge pull request #28 from redneb/use-bracket
986dd99Thomas M. DuBuisson
System/Entropy.hs+2−5
@@ -33,6 +33,7 @@ import System.EntropyNix
33#endif
33#endif
34
34
35import qualified Data.ByteString as B
35import qualified Data.ByteString as B
36+import Control.Exception (bracket)
36
37
37-- |Get a specific number of bytes of cryptographically
38-- |Get a specific number of bytes of cryptographically
38-- secure random data using the system-specific facilities.
39-- secure random data using the system-specific facilities.
@@ -41,8 +42,4 @@ import qualified Data.ByteString as B
41-- Windows. In short, this entropy is considered cryptographically secure
42-- Windows. In short, this entropy is considered cryptographically secure
42-- but not true entropy.
43-- but not true entropy.
43getEntropy :: Int -> IO B.ByteString
44getEntropy :: Int -> IO B.ByteString
44−getEntropy n = do
45+getEntropy = bracket openHandle closeHandle . flip hGetEntropy
45− h <- openHandle
46− e <- hGetEntropy h n
47− closeHandle h
48− return e