Merge pull request #199 from ocheron/proxy-backend

Use Proxy for openBackend
This commit is contained in:
Vincent Hanquez 2017-11-19 16:00:41 +00:00 committed by GitHub
commit c26b331c8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -15,6 +15,7 @@ module Crypto.Random.Entropy.Backend
import Foreign.Ptr import Foreign.Ptr
import Data.Word (Word8) import Data.Word (Word8)
import Crypto.Internal.Proxy
import Crypto.Random.Entropy.Source import Crypto.Random.Entropy.Source
#ifdef SUPPORT_RDRAND #ifdef SUPPORT_RDRAND
import Crypto.Random.Entropy.RDRand import Crypto.Random.Entropy.RDRand
@ -30,12 +31,12 @@ supportedBackends :: [IO (Maybe EntropyBackend)]
supportedBackends = supportedBackends =
[ [
#ifdef SUPPORT_RDRAND #ifdef SUPPORT_RDRAND
openBackend (undefined :: RDRand), openBackend (Proxy :: Proxy RDRand),
#endif #endif
#ifdef WINDOWS #ifdef WINDOWS
openBackend (undefined :: WinCryptoAPI) openBackend (Proxy :: Proxy WinCryptoAPI)
#else #else
openBackend (undefined :: DevRandom), openBackend (undefined :: DevURandom) openBackend (Proxy :: Proxy DevRandom), openBackend (Proxy :: Proxy DevURandom)
#endif #endif
] ]
@ -43,9 +44,9 @@ supportedBackends =
data EntropyBackend = forall b . EntropySource b => EntropyBackend b data EntropyBackend = forall b . EntropySource b => EntropyBackend b
-- | Open a backend handle -- | Open a backend handle
openBackend :: EntropySource b => b -> IO (Maybe EntropyBackend) openBackend :: EntropySource b => Proxy b -> IO (Maybe EntropyBackend)
openBackend b = fmap EntropyBackend `fmap` callOpen b openBackend b = fmap EntropyBackend `fmap` callOpen b
where callOpen :: EntropySource b => b -> IO (Maybe b) where callOpen :: EntropySource b => Proxy b -> IO (Maybe b)
callOpen _ = entropyOpen callOpen _ = entropyOpen
-- | Gather randomness from an open handle -- | Gather randomness from an open handle

View File

@ -224,7 +224,7 @@ Library
Other-modules: Crypto.Hash.SHAKE Other-modules: Crypto.Hash.SHAKE
Crypto.Hash.Blake2 Crypto.Hash.Blake2
Crypto.Internal.Nat Crypto.Internal.Nat
Build-depends: base >= 4.3 && < 5 Build-depends: base >= 4.6 && < 5
, bytestring , bytestring
, memory >= 0.14.5 , memory >= 0.14.5
, foundation >= 0.0.8 , foundation >= 0.0.8