diff --git a/OpenSSL/BIO.hs b/OpenSSL/BIO.hs index 8e5c7d5..557f60b 100644 --- a/OpenSSL/BIO.hs +++ b/OpenSSL/BIO.hs @@ -411,10 +411,10 @@ newBuffer bufSize {- mem ---------------------------------------------------------------------- -} -foreign import capi unsafe "openssl/bio.h BIO_s_mem" +foreign import ccall unsafe "openssl/bio.h BIO_s_mem" s_mem :: IO (Ptr BIO_METHOD) -foreign import capi unsafe "openssl/bio.h BIO_new_mem_buf" +foreign import ccall unsafe "openssl/bio.h BIO_new_mem_buf" _new_mem_buf :: Ptr CChar -> CInt -> IO (Ptr BIO_) @@ -466,7 +466,7 @@ newConstMemLBS lbs {- null --------------------------------------------------------------------- -} -foreign import capi unsafe "openssl/bio.h BIO_s_null" +foreign import ccall unsafe "openssl/bio.h BIO_s_null" s_null :: IO (Ptr BIO_METHOD) -- |@'newNullBIO'@ creates a null BIO sink\/source. Data written to diff --git a/OpenSSL/BN.hsc b/OpenSSL/BN.hsc index 3d0962f..0538de8 100644 --- a/OpenSSL/BN.hsc +++ b/OpenSSL/BN.hsc @@ -244,10 +244,10 @@ withBN :: Integer -> (BigNum -> IO a) -> IO a withBN dec m = bracket (integerToBN dec) (_free . unwrapBN) m foreign import capi unsafe "openssl/bn.h BN_bn2mpi" - _bn2mpi :: Ptr BIGNUM -> Ptr CChar -> IO CInt + _bn2mpi :: Ptr BIGNUM -> Ptr CUChar -> IO CInt foreign import capi unsafe "openssl/bn.h BN_mpi2bn" - _mpi2bn :: Ptr CChar -> CInt -> Ptr BIGNUM -> IO (Ptr BIGNUM) + _mpi2bn :: Ptr CUChar -> CInt -> Ptr BIGNUM -> IO (Ptr BIGNUM) -- |This is an alias to 'bnToInteger'. peekBN :: BigNum -> IO Integer @@ -265,13 +265,13 @@ bnToMPI bn = do bytes <- _bn2mpi (unwrapBN bn) nullPtr allocaBytes (fromIntegral bytes) (\buffer -> do _ <- _bn2mpi (unwrapBN bn) buffer - BS.packCStringLen (buffer, fromIntegral bytes)) + BS.packCStringLen (castPtr buffer, fromIntegral bytes)) -- | Convert an MPI into a BigNum. See bnToMPI for details of the format mpiToBN :: BS.ByteString -> IO BigNum mpiToBN mpi = do BS.useAsCStringLen mpi (\(ptr, len) -> do - _mpi2bn ptr (fromIntegral len) nullPtr) >>= return . wrapBN + _mpi2bn (castPtr ptr) (fromIntegral len) nullPtr) >>= return . wrapBN -- | Convert an Integer to an MPI. See bnToMPI for the format integerToMPI :: Integer -> IO BS.ByteString diff --git a/OpenSSL/EVP/Base64.hs b/OpenSSL/EVP/Base64.hs index 3a058a3..9c4b43d 100644 --- a/OpenSSL/EVP/Base64.hs +++ b/OpenSSL/EVP/Base64.hs @@ -22,9 +22,9 @@ import qualified Data.ByteString.Char8 as B8 import qualified Data.ByteString.Lazy.Char8 as L8 import Data.List #if MIN_VERSION_base(4,5,0) -import Foreign.C.Types (CChar(..), CInt(..)) +import Foreign.C.Types (CUChar(..), CInt(..)) #else -import Foreign.C.Types (CChar, CInt) +import Foreign.C.Types (CUChar, CInt) #endif import Foreign.Ptr (Ptr, castPtr) import System.IO.Unsafe (unsafePerformIO) @@ -50,7 +50,7 @@ nextBlock minLen (xs, src) {- encode -------------------------------------------------------------------- -} foreign import capi unsafe "openssl/evp.h EVP_EncodeBlock" - _EncodeBlock :: Ptr CChar -> Ptr CChar -> CInt -> IO CInt + _EncodeBlock :: Ptr CUChar -> Ptr CUChar -> CInt -> IO CInt encodeBlock :: B8.ByteString -> B8.ByteString @@ -59,7 +59,7 @@ encodeBlock inBS unsafeUseAsCStringLen inBS $ \ (inBuf, inLen) -> createAndTrim maxOutLen $ \ outBuf -> fmap fromIntegral - (_EncodeBlock (castPtr outBuf) inBuf (fromIntegral inLen)) + (_EncodeBlock (castPtr outBuf) (castPtr inBuf) (fromIntegral inLen)) where maxOutLen = (inputLen `div` 3 + 1) * 4 + 1 -- +1: '\0' inputLen = B8.length inBS @@ -104,7 +104,7 @@ encodeBase64LBS inLBS {- decode -------------------------------------------------------------------- -} foreign import capi unsafe "openssl/evp.h EVP_DecodeBlock" - _DecodeBlock :: Ptr CChar -> Ptr CChar -> CInt -> IO CInt + _DecodeBlock :: Ptr CUChar -> Ptr CUChar -> CInt -> IO CInt decodeBlock :: B8.ByteString -> B8.ByteString @@ -113,7 +113,7 @@ decodeBlock inBS unsafePerformIO $ unsafeUseAsCStringLen inBS $ \ (inBuf, inLen) -> createAndTrim (B8.length inBS) $ \ outBuf -> - _DecodeBlock (castPtr outBuf) inBuf (fromIntegral inLen) + _DecodeBlock (castPtr outBuf) (castPtr inBuf) (fromIntegral inLen) >>= \ outLen -> return (fromIntegral outLen - paddingLen) where paddingLen :: Int diff --git a/OpenSSL/EVP/Internal.hsc b/OpenSSL/EVP/Internal.hsc index 1e32b61..700eae9 100644 --- a/OpenSSL/EVP/Internal.hsc +++ b/OpenSSL/EVP/Internal.hsc @@ -66,7 +66,7 @@ import qualified Data.ByteString.Lazy.Internal as L8 import Control.Applicative ((<$>)) #endif import Control.Exception (mask, mask_, bracket, onException) -import Foreign.C.Types (CChar) +import Foreign.C.Types (CChar, CUChar) #if MIN_VERSION_base(4,5,0) import Foreign.C.Types (CInt(..), CUInt(..), CSize(..)) #else @@ -335,10 +335,10 @@ foreign import capi unsafe "openssl/hmac.h HMAC_Init" _hmac_init :: Ptr HMAC_CTX -> Ptr () -> CInt -> Ptr EVP_MD -> IO CInt foreign import capi unsafe "openssl/hmac.h HMAC_Update" - _hmac_update :: Ptr HMAC_CTX -> Ptr CChar -> CInt -> IO CInt + _hmac_update :: Ptr HMAC_CTX -> Ptr CUChar -> CSize -> IO CInt foreign import capi unsafe "openssl/hmac.h HMAC_Final" - _hmac_final :: Ptr HMAC_CTX -> Ptr CChar -> Ptr CInt -> IO CUInt + _hmac_final :: Ptr HMAC_CTX -> Ptr CUChar -> Ptr CUInt -> IO CUInt foreign import capi unsafe "HsOpenSSL &HsOpenSSL_HMAC_CTX_free" _hmac_ctx_free :: FunPtr (Ptr HMAC_CTX -> IO ()) diff --git a/cbits/HsOpenSSL.h b/cbits/HsOpenSSL.h index 59b5833..c56adc7 100644 --- a/cbits/HsOpenSSL.h +++ b/cbits/HsOpenSSL.h @@ -20,18 +20,6 @@ #include #include -/* A dirty hack to work around for broken versions of Cabal: - * https://github.com/phonohawk/HsOpenSSL/issues/8 - * - * The trick is to abuse the fact that -Icbits is (almost) always - * passed to hsc2hs so we can reach the cabal_macros.h from cbits, but - * see #23, #24 and #25... - */ -#if !defined(MIN_VERSION_base) && \ - !defined(HSOPENSSL_NEED_NOT_INCLUDE_CABAL_MACROS_H) -# include "../dist/build/autogen/cabal_macros.h" -#endif - /* LibreSSL *******************************************************************/ #if (defined LIBRESSL_VERSION_NUMBER && OPENSSL_VERSION_NUMBER == 0x20000000L) #undef OPENSSL_VERSION_NUMBER