aboutsummaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2018-08-02 17:19:33 -0400
committerGravatar Benjamin Barenblat <bbaren@google.com>2018-08-02 17:19:33 -0400
commit44a6b5738f73b5281c3630c507aeece75e6ee952 (patch)
treec55ae9fe7260b7f16244b5dd220bc7f806a9fc79 /src/Data
parent2152e7728db7e0cf86ea23d29a05294af24b6898 (diff)
Factor out common char* ↔ unsigned char* cast
Diffstat (limited to 'src/Data')
-rw-r--r--src/Data/Digest.hs7
-rw-r--r--src/Data/HMAC.hs7
2 files changed, 2 insertions, 12 deletions
diff --git a/src/Data/Digest.hs b/src/Data/Digest.hs
index 2d06389..03026fb 100644
--- a/src/Data/Digest.hs
+++ b/src/Data/Digest.hs
@@ -22,13 +22,11 @@ module Data.Digest
) where
import qualified Data.ByteString.Lazy as ByteString.Lazy
-import Foreign (Ptr)
-import Foreign.C.Types
import Foreign.Marshal.Unsafe (unsafeLocalState)
-import Unsafe.Coerce (unsafeCoerce)
import BTLS.BoringSSL.Base
import BTLS.BoringSSL.Digest
+import BTLS.Cast (asCUCharBuf)
import Data.Digest.Internal
type LazyByteString = ByteString.Lazy.ByteString
@@ -56,6 +54,3 @@ hash (Algorithm md) =
-- we're going to cheat and let Haskell reinterpret-cast 'mdOut' to 'Ptr
-- CUChar.
evpDigestFinalEx ctx (asCUCharBuf mdOut) pOutSize
-
- asCUCharBuf :: Ptr CChar -> Ptr CUChar
- asCUCharBuf = unsafeCoerce
diff --git a/src/Data/HMAC.hs b/src/Data/HMAC.hs
index 29b6ce0..a6b72fe 100644
--- a/src/Data/HMAC.hs
+++ b/src/Data/HMAC.hs
@@ -21,13 +21,11 @@ module Data.HMAC
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as ByteString.Lazy
import qualified Data.ByteString.Unsafe as ByteString
-import Foreign (Ptr)
-import Foreign.C.Types
import Foreign.Marshal.Unsafe (unsafeLocalState)
-import Unsafe.Coerce (unsafeCoerce)
import BTLS.BoringSSL.Base
import BTLS.BoringSSL.HMAC
+import BTLS.Cast (asCUCharBuf)
import BTLS.ConstantTimeEquals (constantTimeEquals)
import BTLS.Types (SecretKey(SecretKey))
import Data.Digest.Internal
@@ -65,6 +63,3 @@ hmac (Algorithm md) (SecretKey key) =
-- in Data.Digest, we'll let Haskell reinterpret-cast the buffers.
update ctx buf len = hmacUpdate ctx (asCUCharBuf buf) len
finalize ctx hmacOut pOutSize = hmacFinal ctx (asCUCharBuf hmacOut) pOutSize
-
- asCUCharBuf :: Ptr CChar -> Ptr CUChar
- asCUCharBuf = unsafeCoerce