From 015079075e1e156d5934f4e716a51eb284289b5d Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Tue, 4 Sep 2018 18:53:20 -0400 Subject: Marshal `ForeignPtr` to `Ptr` within c2hs code --- src/Data/HMAC.hs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/Data/HMAC.hs') 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) -- cgit v1.2.3