diff options
Diffstat (limited to 'src/Data')
-rw-r--r-- | src/Data/Digest.hs | 10 | ||||
-rw-r--r-- | src/Data/HMAC.hs | 12 |
2 files changed, 9 insertions, 13 deletions
diff --git a/src/Data/Digest.hs b/src/Data/Digest.hs index a17c438..594fef1 100644 --- a/src/Data/Digest.hs +++ b/src/Data/Digest.hs @@ -40,7 +40,6 @@ module Data.Digest import qualified Data.ByteString.Lazy as Lazy (ByteString) import qualified Data.ByteString.Lazy as ByteString.Lazy -import Foreign (withForeignPtr) import Foreign.Marshal.Unsafe (unsafeLocalState) import BTLS.BoringSSL.Base @@ -88,8 +87,7 @@ sha512 = Algorithm evpSHA512 hash :: Algorithm -> Lazy.ByteString -> Digest hash (Algorithm md) bytes = unsafeLocalState $ do - ctxFP <- mallocEVPMDCtx - withForeignPtr ctxFP $ \ctx -> do - evpDigestInitEx ctx md noEngine - mapM_ (evpDigestUpdate ctx) (ByteString.Lazy.toChunks bytes) - Digest <$> onBufferOfMaxSize evpMaxMDSize (evpDigestFinalEx ctx) + ctx <- mallocEVPMDCtx + evpDigestInitEx ctx md noEngine + mapM_ (evpDigestUpdate ctx) (ByteString.Lazy.toChunks bytes) + Digest <$> onBufferOfMaxSize evpMaxMDSize (evpDigestFinalEx ctx) diff --git a/src/Data/HMAC.hs b/src/Data/HMAC.hs index fb67817..c6edca3 100644 --- a/src/Data/HMAC.hs +++ b/src/Data/HMAC.hs @@ -51,7 +51,6 @@ import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as Lazy (ByteString) import qualified Data.ByteString.Lazy as ByteString.Lazy import qualified Data.ByteString.Unsafe as ByteString -import Foreign (withForeignPtr) import Foreign.Marshal.Unsafe (unsafeLocalState) import BTLS.BoringSSL.Base @@ -80,9 +79,8 @@ instance Show HMAC where -- | Creates an HMAC according to the given 'Algorithm'. hmac :: Algorithm -> SecretKey -> Lazy.ByteString -> Either [Error] HMAC hmac (Algorithm md) (SecretKey key) bytes = - unsafeLocalState $ do - ctxFP <- mallocHMACCtx - withForeignPtr ctxFP $ \ctx -> runExceptT $ do - check $ hmacInitEx ctx key md noEngine - lift $ mapM_ (hmacUpdate ctx) (ByteString.Lazy.toChunks bytes) - lift $ HMAC <$> onBufferOfMaxSize evpMaxMDSize (hmacFinal ctx) + unsafeLocalState $ runExceptT $ do + ctx <- lift mallocHMACCtx + check $ hmacInitEx ctx key md noEngine + lift $ mapM_ (hmacUpdate ctx) (ByteString.Lazy.toChunks bytes) + lift $ HMAC <$> onBufferOfMaxSize evpMaxMDSize (hmacFinal ctx) |