aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Digest.hs
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@google.com>2018-08-23 17:24:47 -0400
committerGravatar Benjamin Barenblat <bbaren@google.com>2018-08-23 17:24:47 -0400
commitd1a85eb87934d348c9789aec59c751fa615ec363 (patch)
tree09c72e290df883c1e2d4c7ea2ccf0b1470668ca2 /src/Data/Digest.hs
parent3be302655bc7e31805af4525d78beb6abfed9a5d (diff)
Clean up casts
Use unsigned char buffers more pervasively throughout the code. This removes most calls to `asCUCharBuf`, isolating `unsafeCoerce` further. By making some type signatures slightly more flexible, also eliminate most explicit integer conversions.
Diffstat (limited to 'src/Data/Digest.hs')
-rw-r--r--src/Data/Digest.hs13
1 files changed, 2 insertions, 11 deletions
diff --git a/src/Data/Digest.hs b/src/Data/Digest.hs
index 0587d2b..3e6f263 100644
--- a/src/Data/Digest.hs
+++ b/src/Data/Digest.hs
@@ -27,7 +27,6 @@ import Foreign.Marshal.Unsafe (unsafeLocalState)
import BTLS.BoringSSL.Base
import BTLS.BoringSSL.Digest
import BTLS.BoringSSLPatterns (initUpdateFinalize)
-import BTLS.Cast (asCUCharBuf)
import BTLS.Types (Algorithm(Algorithm), Digest(Digest))
type LazyByteString = ByteString.Lazy.ByteString
@@ -45,13 +44,5 @@ hash :: Algorithm -> LazyByteString -> Digest
hash (Algorithm md) =
Digest
. unsafeLocalState
- . initUpdateFinalize mallocEVPMDCtx initialize evpDigestUpdate finalize
- where
- initialize ctx = evpDigestInitEx ctx md noEngine
-
- finalize ctx mdOut pOutSize =
- -- 'mdOut' is a 'Ptr CChar'. However, to make life more interesting,
- -- 'evpDigestFinalEx' requires a 'Ptr CUChar'. To work around this,
- -- we're going to cheat and let Haskell reinterpret-cast 'mdOut' to 'Ptr
- -- CUChar.
- evpDigestFinalEx ctx (asCUCharBuf mdOut) pOutSize
+ . initUpdateFinalize mallocEVPMDCtx initialize evpDigestUpdate evpDigestFinalEx
+ where initialize ctx = evpDigestInitEx ctx md noEngine