From d1a85eb87934d348c9789aec59c751fa615ec363 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Thu, 23 Aug 2018 17:24:47 -0400 Subject: 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. --- src/System/Random/Crypto.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/System/Random/Crypto.hs') diff --git a/src/System/Random/Crypto.hs b/src/System/Random/Crypto.hs index ca2fba5..903f7aa 100644 --- a/src/System/Random/Crypto.hs +++ b/src/System/Random/Crypto.hs @@ -17,15 +17,14 @@ module System.Random.Crypto ) where import Data.ByteString (ByteString) -import qualified Data.ByteString as ByteString import Foreign (allocaArray) import BTLS.BoringSSL.Rand (randBytes) -import BTLS.Cast (asCUCharBuf) +import BTLS.Buffer (packCUStringLen) -- | Generates a cryptographically random buffer of the specified size. randomBytes :: Int -> IO ByteString randomBytes len = allocaArray len $ \pBuf -> do - randBytes (asCUCharBuf pBuf) (fromIntegral len) - ByteString.packCStringLen (pBuf, len) + randBytes pBuf (fromIntegral len) + packCUStringLen (pBuf, len) -- cgit v1.2.3