Skip to content

Commit

Permalink
Merge pull request #27 from eskimor/warnings
Browse files Browse the repository at this point in the history
Added warning about resource leakage
  • Loading branch information
TomMD committed May 11, 2017
2 parents 51d5235 + 36d120b commit 6a74ec1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Crypto/Classes.hs
Expand Up @@ -490,6 +490,7 @@ class AsymCipher p v | p -> v, v -> p where
privateKeyLength :: v -> BitLength

-- |Build a pair of asymmetric keys using the system random generator.
-- WARNING: This function opens a file handle which will never be closed!
buildKeyPairIO :: AsymCipher p v => BitLength -> IO (Either GenError (p,v))
buildKeyPairIO bl = do
g <- newGenIO :: IO SystemRandom
Expand Down Expand Up @@ -542,6 +543,7 @@ class (Serialize p, Serialize v) => Signing p v | p -> v, v -> p where
verifyingKeyLength :: p -> BitLength

-- |Build a signing key using the system random generator
-- WARNING: This function opens a file handle which will never be closed!
buildSigningKeyPairIO :: (Signing p v) => BitLength -> IO (Either GenError (p,v))
buildSigningKeyPairIO bl = do
g <- newGenIO :: IO SystemRandom
Expand Down
4 changes: 3 additions & 1 deletion Crypto/Random.hs
Expand Up @@ -162,6 +162,7 @@ class CryptoRandomGen g where

-- |By default this uses "System.Entropy" to obtain
-- entropy for `newGen`.
-- WARNING: The default implementation opens a file handle which will never be closed!
newGenIO :: IO g
newGenIO = go 0
where
Expand All @@ -178,7 +179,8 @@ class CryptoRandomGen g where
Left _ -> go (i+1)
Right g -> return (g `asProxyTypeOf` p)

-- |Get a random number generator based on the standard system entropy source
-- | Get a random number generator based on the standard system entropy source
-- WARNING: This function opens a file handle which will never be closed!
getSystemGen :: IO SystemRandom
getSystemGen = do
ch <- openHandle
Expand Down

0 comments on commit 6a74ec1

Please sign in to comment.