Skip to content

Commit

Permalink
Merge pull request #28 from redneb/use-bracket
Browse files Browse the repository at this point in the history
Use bracket to ensure async exception safety
  • Loading branch information
TomMD committed Mar 25, 2016
2 parents 5422644 + f33ccef commit 986dd99
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions System/Entropy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import System.EntropyNix
#endif

import qualified Data.ByteString as B
import Control.Exception (bracket)

-- |Get a specific number of bytes of cryptographically
-- secure random data using the system-specific facilities.
Expand All @@ -41,8 +42,4 @@ import qualified Data.ByteString as B
-- Windows. In short, this entropy is considered cryptographically secure
-- but not true entropy.
getEntropy :: Int -> IO B.ByteString
getEntropy n = do
h <- openHandle
e <- hGetEntropy h n
closeHandle h
return e
getEntropy = bracket openHandle closeHandle . flip hGetEntropy

0 comments on commit 986dd99

Please sign in to comment.