Merge pull request #20 from rblaze/devrandom
Use non-blocking IO with /dev/random.
This commit is contained in:
commit
8f01f2ea64
@ -31,7 +31,7 @@ newtype DevURandom = DevURandom DeviceName
|
||||
instance EntropySource DevRandom where
|
||||
entropyOpen = fmap DevRandom `fmap` testOpen "/dev/random"
|
||||
entropyGather (DevRandom name) ptr n =
|
||||
withDev name $ \h -> gatherDevEntropy h ptr n
|
||||
withDev name $ \h -> gatherDevEntropyNonBlock h ptr n
|
||||
entropyClose (DevRandom _) = return ()
|
||||
|
||||
instance EntropySource DevURandom where
|
||||
@ -67,3 +67,8 @@ gatherDevEntropy :: H -> Ptr Word8 -> Int -> IO Int
|
||||
gatherDevEntropy h ptr sz =
|
||||
(fromIntegral `fmap` hGetBufSome h ptr (fromIntegral sz))
|
||||
`E.catch` \(_ :: IOException) -> return 0
|
||||
|
||||
gatherDevEntropyNonBlock :: H -> Ptr Word8 -> Int -> IO Int
|
||||
gatherDevEntropyNonBlock h ptr sz =
|
||||
(fromIntegral `fmap` hGetBufNonBlocking h ptr (fromIntegral sz))
|
||||
`E.catch` \(_ :: IOException) -> return 0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user