diff --git a/Crypto/Hash/Internal.hs b/Crypto/Hash/Internal.hs index 9ba688a..5ec625f 100644 --- a/Crypto/Hash/Internal.hs +++ b/Crypto/Hash/Internal.hs @@ -1,24 +1,9 @@ -{-# LANGUAGE CPP #-} - -- | -- Module : Crypto.Hash.Internal -- License : BSD-style -- Maintainer : Vincent Hanquez -- Stability : experimental -- Portability : unknown -module Crypto.Hash.Internal where - -import System.IO.Unsafe - --- | perform io for hashes that do allocation and ffi. --- unsafeDupablePerformIO is used when possible as the --- computation is pure and the output is directly linked --- to the input. we also do not modify anything after it has --- been returned to the user. -unsafeDoIO :: IO a -> a -#if __GLASGOW_HASKELL__ > 704 -unsafeDoIO = unsafeDupablePerformIO -#else -unsafeDoIO = unsafePerformIO -#endif +module Crypto.Hash.Internal (unsafeDoIO) where +import Crypto.Internal.Compat (unsafeDoIO) diff --git a/Crypto/Internal/Compat.hs b/Crypto/Internal/Compat.hs new file mode 100644 index 0000000..e89a66b --- /dev/null +++ b/Crypto/Internal/Compat.hs @@ -0,0 +1,28 @@ +-- | +-- Module : Crypto.Internal.Compat +-- License : BSD-style +-- Maintainer : Vincent Hanquez +-- Stability : stable +-- Portability : Good +-- +-- This module try to keep all the difference between versions of base +-- or other needed packages, so that modules don't need to use CPP +-- +{-# LANGUAGE CPP #-} +module Crypto.Internal.Compat + ( unsafeDoIO + ) where + +import System.IO.Unsafe + +-- | perform io for hashes that do allocation and ffi. +-- unsafeDupablePerformIO is used when possible as the +-- computation is pure and the output is directly linked +-- to the input. we also do not modify anything after it has +-- been returned to the user. +unsafeDoIO :: IO a -> a +#if __GLASGOW_HASKELL__ > 704 +unsafeDoIO = unsafeDupablePerformIO +#else +unsafeDoIO = unsafePerformIO +#endif diff --git a/cryptonite.cabal b/cryptonite.cabal index 2af574b..9c13737 100644 --- a/cryptonite.cabal +++ b/cryptonite.cabal @@ -58,6 +58,7 @@ Library , Crypto.Hash.Types , Crypto.Random.Entropy.Source , Crypto.Random.Entropy.Backend + , Crypto.Internal.Compat Build-depends: base >= 4.5 && < 5 , bytestring , securemem