aboutsummaryrefslogtreecommitdiff
path: root/src/Data/HMAC.hs
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2018-09-04 18:53:20 -0400
committerGravatar Benjamin Barenblat <bbaren@google.com>2018-09-04 18:53:20 -0400
commit015079075e1e156d5934f4e716a51eb284289b5d (patch)
tree17dd43c33e0af2696dc1a61c2a9abe6c0667e1d4 /src/Data/HMAC.hs
parent2e7bd84469eba730f24dd3e448cca22f5aed16f4 (diff)
Marshal `ForeignPtr` to `Ptr` within c2hs code
Diffstat (limited to 'src/Data/HMAC.hs')
-rw-r--r--src/Data/HMAC.hs12
1 files changed, 5 insertions, 7 deletions
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)