Skip to content

Commit 57b22b1

Browse files
authored
Merge pull request #94 from glguy/glguy/pointer-fixes
Fix up incompatible pointer issues
2 parents b7a4999 + 7c90fc3 commit 57b22b1

File tree

5 files changed

+16
-28
lines changed

5 files changed

+16
-28
lines changed

OpenSSL/BIO.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,10 @@ newBuffer bufSize
411411

412412
{- mem ---------------------------------------------------------------------- -}
413413

414-
foreign import capi unsafe "openssl/bio.h BIO_s_mem"
414+
foreign import ccall unsafe "openssl/bio.h BIO_s_mem"
415415
s_mem :: IO (Ptr BIO_METHOD)
416416

417-
foreign import capi unsafe "openssl/bio.h BIO_new_mem_buf"
417+
foreign import ccall unsafe "openssl/bio.h BIO_new_mem_buf"
418418
_new_mem_buf :: Ptr CChar -> CInt -> IO (Ptr BIO_)
419419

420420

@@ -466,7 +466,7 @@ newConstMemLBS lbs
466466

467467
{- null --------------------------------------------------------------------- -}
468468

469-
foreign import capi unsafe "openssl/bio.h BIO_s_null"
469+
foreign import ccall unsafe "openssl/bio.h BIO_s_null"
470470
s_null :: IO (Ptr BIO_METHOD)
471471

472472
-- |@'newNullBIO'@ creates a null BIO sink\/source. Data written to

OpenSSL/BN.hsc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ withBN :: Integer -> (BigNum -> IO a) -> IO a
244244
withBN dec m = bracket (integerToBN dec) (_free . unwrapBN) m
245245

246246
foreign import capi unsafe "openssl/bn.h BN_bn2mpi"
247-
_bn2mpi :: Ptr BIGNUM -> Ptr CChar -> IO CInt
247+
_bn2mpi :: Ptr BIGNUM -> Ptr CUChar -> IO CInt
248248

249249
foreign import capi unsafe "openssl/bn.h BN_mpi2bn"
250-
_mpi2bn :: Ptr CChar -> CInt -> Ptr BIGNUM -> IO (Ptr BIGNUM)
250+
_mpi2bn :: Ptr CUChar -> CInt -> Ptr BIGNUM -> IO (Ptr BIGNUM)
251251

252252
-- |This is an alias to 'bnToInteger'.
253253
peekBN :: BigNum -> IO Integer
@@ -265,13 +265,13 @@ bnToMPI bn = do
265265
bytes <- _bn2mpi (unwrapBN bn) nullPtr
266266
allocaBytes (fromIntegral bytes) (\buffer -> do
267267
_ <- _bn2mpi (unwrapBN bn) buffer
268-
BS.packCStringLen (buffer, fromIntegral bytes))
268+
BS.packCStringLen (castPtr buffer, fromIntegral bytes))
269269

270270
-- | Convert an MPI into a BigNum. See bnToMPI for details of the format
271271
mpiToBN :: BS.ByteString -> IO BigNum
272272
mpiToBN mpi = do
273273
BS.useAsCStringLen mpi (\(ptr, len) -> do
274-
_mpi2bn ptr (fromIntegral len) nullPtr) >>= return . wrapBN
274+
_mpi2bn (castPtr ptr) (fromIntegral len) nullPtr) >>= return . wrapBN
275275

276276
-- | Convert an Integer to an MPI. See bnToMPI for the format
277277
integerToMPI :: Integer -> IO BS.ByteString

OpenSSL/EVP/Base64.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import qualified Data.ByteString.Char8 as B8
2222
import qualified Data.ByteString.Lazy.Char8 as L8
2323
import Data.List
2424
#if MIN_VERSION_base(4,5,0)
25-
import Foreign.C.Types (CChar(..), CInt(..))
25+
import Foreign.C.Types (CUChar(..), CInt(..))
2626
#else
27-
import Foreign.C.Types (CChar, CInt)
27+
import Foreign.C.Types (CUChar, CInt)
2828
#endif
2929
import Foreign.Ptr (Ptr, castPtr)
3030
import System.IO.Unsafe (unsafePerformIO)
@@ -50,7 +50,7 @@ nextBlock minLen (xs, src)
5050
{- encode -------------------------------------------------------------------- -}
5151

5252
foreign import capi unsafe "openssl/evp.h EVP_EncodeBlock"
53-
_EncodeBlock :: Ptr CChar -> Ptr CChar -> CInt -> IO CInt
53+
_EncodeBlock :: Ptr CUChar -> Ptr CUChar -> CInt -> IO CInt
5454

5555

5656
encodeBlock :: B8.ByteString -> B8.ByteString
@@ -59,7 +59,7 @@ encodeBlock inBS
5959
unsafeUseAsCStringLen inBS $ \ (inBuf, inLen) ->
6060
createAndTrim maxOutLen $ \ outBuf ->
6161
fmap fromIntegral
62-
(_EncodeBlock (castPtr outBuf) inBuf (fromIntegral inLen))
62+
(_EncodeBlock (castPtr outBuf) (castPtr inBuf) (fromIntegral inLen))
6363
where
6464
maxOutLen = (inputLen `div` 3 + 1) * 4 + 1 -- +1: '\0'
6565
inputLen = B8.length inBS
@@ -104,7 +104,7 @@ encodeBase64LBS inLBS
104104
{- decode -------------------------------------------------------------------- -}
105105

106106
foreign import capi unsafe "openssl/evp.h EVP_DecodeBlock"
107-
_DecodeBlock :: Ptr CChar -> Ptr CChar -> CInt -> IO CInt
107+
_DecodeBlock :: Ptr CUChar -> Ptr CUChar -> CInt -> IO CInt
108108

109109

110110
decodeBlock :: B8.ByteString -> B8.ByteString
@@ -113,7 +113,7 @@ decodeBlock inBS
113113
unsafePerformIO $
114114
unsafeUseAsCStringLen inBS $ \ (inBuf, inLen) ->
115115
createAndTrim (B8.length inBS) $ \ outBuf ->
116-
_DecodeBlock (castPtr outBuf) inBuf (fromIntegral inLen)
116+
_DecodeBlock (castPtr outBuf) (castPtr inBuf) (fromIntegral inLen)
117117
>>= \ outLen -> return (fromIntegral outLen - paddingLen)
118118
where
119119
paddingLen :: Int

OpenSSL/EVP/Internal.hsc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import qualified Data.ByteString.Lazy.Internal as L8
6666
import Control.Applicative ((<$>))
6767
#endif
6868
import Control.Exception (mask, mask_, bracket, onException)
69-
import Foreign.C.Types (CChar)
69+
import Foreign.C.Types (CChar, CUChar)
7070
#if MIN_VERSION_base(4,5,0)
7171
import Foreign.C.Types (CInt(..), CUInt(..), CSize(..))
7272
#else
@@ -335,10 +335,10 @@ foreign import capi unsafe "openssl/hmac.h HMAC_Init"
335335
_hmac_init :: Ptr HMAC_CTX -> Ptr () -> CInt -> Ptr EVP_MD -> IO CInt
336336

337337
foreign import capi unsafe "openssl/hmac.h HMAC_Update"
338-
_hmac_update :: Ptr HMAC_CTX -> Ptr CChar -> CInt -> IO CInt
338+
_hmac_update :: Ptr HMAC_CTX -> Ptr CUChar -> CSize -> IO CInt
339339

340340
foreign import capi unsafe "openssl/hmac.h HMAC_Final"
341-
_hmac_final :: Ptr HMAC_CTX -> Ptr CChar -> Ptr CInt -> IO CUInt
341+
_hmac_final :: Ptr HMAC_CTX -> Ptr CUChar -> Ptr CUInt -> IO CUInt
342342

343343
foreign import capi unsafe "HsOpenSSL &HsOpenSSL_HMAC_CTX_free"
344344
_hmac_ctx_free :: FunPtr (Ptr HMAC_CTX -> IO ())

cbits/HsOpenSSL.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@
2020
#include <openssl/x509v3.h>
2121
#include <openssl/dsa.h>
2222

23-
/* A dirty hack to work around for broken versions of Cabal:
24-
* https://github.com/phonohawk/HsOpenSSL/issues/8
25-
*
26-
* The trick is to abuse the fact that -Icbits is (almost) always
27-
* passed to hsc2hs so we can reach the cabal_macros.h from cbits, but
28-
* see #23, #24 and #25...
29-
*/
30-
#if !defined(MIN_VERSION_base) && \
31-
!defined(HSOPENSSL_NEED_NOT_INCLUDE_CABAL_MACROS_H)
32-
# include "../dist/build/autogen/cabal_macros.h"
33-
#endif
34-
3523
/* LibreSSL *******************************************************************/
3624
#if (defined LIBRESSL_VERSION_NUMBER && OPENSSL_VERSION_NUMBER == 0x20000000L)
3725
#undef OPENSSL_VERSION_NUMBER

0 commit comments

Comments
 (0)