Permalink
Browse files

Update to 6.8.1

Numerous changes to get everything working with 6.8.1:
  * Update .cabal file to reflect the new Cabal file format and the split base
    libraries. The use of -fglasgow-ext is unfortunate, but there's no -X flag
    for unpacked tuple support.
  * Changes comming from the ByteString interface updates: many renames of
    LazyByteString and switching from LPS to the new internal representation.

darcs-hash:20071105005113-19166-a38629c4ba2b7bf24cf50372c31a5d9a0f75190d.gz
  • Loading branch information...
1 parent 76ddc6e commit e75a99a6a36744a7dbaa7ccfc0f6775388f4e9ea @agl agl committed Nov 5, 2007
View
@@ -5,65 +5,75 @@ Description:
generate RSA and DSA keys, read and write PEM files, generate
message digests, sign and verify messages, encrypt and decrypt
messages.
-Version: 0.3
+Version: 0.3.1
License: PublicDomain
License-File: COPYING
Author: PHO <phonohawk at ps dot sakura dot ne dot jp>
Maintainer: PHO <phonohawk at ps dot sakura dot ne dot jp>
Stability: experimental
Homepage: http://ccm.sherry.jp/HsOpenSSL/
Category: Cryptography
-Tested-With: GHC == 6.6.1
-Build-Depends:
- base, time >= 1.1.1
-Exposed-Modules:
- OpenSSL
- OpenSSL.BN
- OpenSSL.EVP.Base64
- OpenSSL.EVP.Cipher
- OpenSSL.EVP.Digest
- OpenSSL.EVP.Open
- OpenSSL.EVP.PKey
- OpenSSL.EVP.Seal
- OpenSSL.EVP.Sign
- OpenSSL.EVP.Verify
- OpenSSL.Cipher
- OpenSSL.PEM
- OpenSSL.PKCS7
- OpenSSL.Random
- OpenSSL.DSA
- OpenSSL.RSA
- OpenSSL.X509
- OpenSSL.X509.Revocation
- OpenSSL.X509.Request
- OpenSSL.X509.Store
-Other-Modules:
- OpenSSL.ASN1
- OpenSSL.BIO
- OpenSSL.ERR
- OpenSSL.Objects
- OpenSSL.SSL
- OpenSSL.Stack
- OpenSSL.Utils
- OpenSSL.X509.Name
-Extensions:
- ForeignFunctionInterface, EmptyDataDecls
-ghc-options:
- -O2 -fwarn-unused-imports
-C-Sources:
- cbits/HsOpenSSL.c
-Include-Dirs:
- cbits
-Install-Includes:
- HsOpenSSL.h
+Tested-With: GHC == 6.8.1
+Cabal-Version: >= 1.2
+
Extra-Source-Files:
- AUTHORS
- HsOpenSSL.buildinfo.in
- NEWS
- cbits/HsOpenSSL.h
- configure
- configure.ac
- examples/Makefile
- examples/GenRSAKey.hs
- examples/HelloWorld.hs
- examples/PKCS7.hs
+ AUTHORS
+ HsOpenSSL.buildinfo.in
+ NEWS
+ cbits/HsOpenSSL.h
+ configure
+ configure.ac
+ examples/Makefile
+ examples/GenRSAKey.hs
+ examples/HelloWorld.hs
+ examples/PKCS7.hs
+
+flag splitBase
+ description: Choose the new smaller, split-up base package.
+
+Library
+ if flag(splitBase)
+ build-depends: base >= 3, bytestring, time >= 1.1.1, old-locale
+ else
+ build-depends: base < 3, time >= 1.1.1
+
+ Exposed-Modules:
+ OpenSSL
+ OpenSSL.BN
+ OpenSSL.EVP.Base64
+ OpenSSL.EVP.Cipher
+ OpenSSL.EVP.Digest
+ OpenSSL.EVP.Open
+ OpenSSL.EVP.PKey
+ OpenSSL.EVP.Seal
+ OpenSSL.EVP.Sign
+ OpenSSL.EVP.Verify
+ OpenSSL.Cipher
+ OpenSSL.PEM
+ OpenSSL.PKCS7
+ OpenSSL.Random
+ OpenSSL.DSA
+ OpenSSL.RSA
+ OpenSSL.X509
+ OpenSSL.X509.Revocation
+ OpenSSL.X509.Request
+ OpenSSL.X509.Store
+ Other-Modules:
+ OpenSSL.ASN1
+ OpenSSL.BIO
+ OpenSSL.ERR
+ OpenSSL.Objects
+ OpenSSL.SSL
+ OpenSSL.Stack
+ OpenSSL.Utils
+ OpenSSL.X509.Name
+ Extensions:
+ ForeignFunctionInterface, EmptyDataDecls, MagicHash
+ ghc-options:
+ -O2 -fwarn-unused-imports -fglasgow-exts
+ C-Sources:
+ cbits/HsOpenSSL.c
+ Include-Dirs:
+ cbits
+ Install-Includes:
+ HsOpenSSL.h
View
@@ -72,7 +72,8 @@ module OpenSSL.BIO
where
import Control.Monad
-import Data.ByteString.Base
+import Data.ByteString.Internal (createAndTrim, toForeignPtr)
+import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Lazy.Char8 as L8
import Foreign hiding (new)
@@ -233,7 +234,7 @@ bioRead bio
-- |@'bioReadBS' bio len@ attempts to read @len@ bytes from @bio@,
-- then return a ByteString. The actual length of result may be less
-- than @len@.
-bioReadBS :: BIO -> Int -> IO ByteString
+bioReadBS :: BIO -> Int -> IO B8.ByteString
bioReadBS bio maxLen
= withBioPtr bio $ \ bioPtr ->
createAndTrim maxLen $ \ bufPtr ->
@@ -248,8 +249,8 @@ bioReadBS bio maxLen
-- |@'bioReadLBS' bio@ lazily reads all data in @bio@, then return a
-- LazyByteString.
-bioReadLBS :: BIO -> IO LazyByteString
-bioReadLBS bio = lazyRead >>= return . LPS
+bioReadLBS :: BIO -> IO L8.ByteString
+bioReadLBS bio = lazyRead >>= return . L8.fromChunks
where
chunkSize = 32 * 1024
@@ -279,7 +280,7 @@ bioGets bio maxLen
= liftM B8.unpack (bioGetsBS bio maxLen)
-- |'bioGetsBS' does the same as 'bioGets' but returns ByteString.
-bioGetsBS :: BIO -> Int -> IO ByteString
+bioGetsBS :: BIO -> Int -> IO B8.ByteString
bioGetsBS bio maxLen
= withBioPtr bio $ \ bioPtr ->
createAndTrim maxLen $ \ bufPtr ->
@@ -294,9 +295,9 @@ bioGetsBS bio maxLen
-- |'bioGetsLBS' does the same as 'bioGets' but returns
-- LazyByteString.
-bioGetsLBS :: BIO -> Int -> IO LazyByteString
+bioGetsLBS :: BIO -> Int -> IO L8.ByteString
bioGetsLBS bio maxLen
- = bioGetsBS bio maxLen >>= \ bs -> (return . LPS) [bs]
+ = bioGetsBS bio maxLen >>= \ bs -> (return . L8.fromChunks) [bs]
-- |@'bioWrite' bio str@ lazily writes entire @str@ to @bio@. The
-- string doesn't necessarily have to be finite.
@@ -305,7 +306,7 @@ bioWrite bio str
= (return . L8.pack) str >>= bioWriteLBS bio
-- |@'bioWriteBS' bio bs@ writes @bs@ to @bio@.
-bioWriteBS :: BIO -> ByteString -> IO ()
+bioWriteBS :: BIO -> B8.ByteString -> IO ()
bioWriteBS bio bs
= withBioPtr bio $ \ bioPtr ->
unsafeUseAsCStringLen bs $ \ (buf, len) ->
@@ -320,9 +321,9 @@ bioWriteBS bio bs
-- |@'bioWriteLBS' bio lbs@ lazily writes entire @lbs@ to @bio@. The
-- string doesn't necessarily have to be finite.
-bioWriteLBS :: BIO -> LazyByteString -> IO ()
-bioWriteLBS bio (LPS chunks)
- = mapM_ (bioWriteBS bio) chunks
+bioWriteLBS :: BIO -> L8.ByteString -> IO ()
+bioWriteLBS bio lbs
+ = mapM_ (bioWriteBS bio) $ L8.toChunks lbs
{- base64 ------------------------------------------------------------------- -}
@@ -436,7 +437,7 @@ newConstMem str
= (return . B8.pack) str >>= newConstMemBS
-- |@'newConstMemBS' bs@ is like 'newConstMem' but takes a ByteString.
-newConstMemBS :: ByteString -> IO BIO
+newConstMemBS :: B8.ByteString -> IO BIO
newConstMemBS bs
= let (foreignBuf, off, len) = toForeignPtr bs
in
@@ -452,9 +453,9 @@ newConstMemBS bs
-- |@'newConstMemLBS' lbs@ is like 'newConstMem' but takes a
-- LazyByteString.
-newConstMemLBS :: LazyByteString -> IO BIO
-newConstMemLBS (LPS bss)
- = (return . B8.concat) bss >>= newConstMemBS
+newConstMemLBS :: L8.ByteString -> IO BIO
+newConstMemLBS lbs
+ = (return . B8.concat . L8.toChunks) lbs >>= newConstMemBS
{- null --------------------------------------------------------------------- -}
@@ -470,4 +471,4 @@ foreign import ccall unsafe "BIO_s_null"
-- source\/sink BIO this can be achieved by adding a null sink BIO to
-- the end of the chain.
newNullBIO :: IO BIO
-newNullBIO = s_null >>= new
+newNullBIO = s_null >>= new
View
@@ -1,3 +1,5 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+
#include "HsOpenSSL.h"
-- #prune
@@ -264,7 +266,7 @@ bnToMPI bn = do
bytes <- _bn2mpi (unwrapBN bn) nullPtr
allocaBytes (fromIntegral bytes) (\buffer -> do
_bn2mpi (unwrapBN bn) buffer
- BS.copyCStringLen (buffer, fromIntegral bytes))
+ BS.packCStringLen (buffer, fromIntegral bytes))
-- | Convert an MPI into a BigNum. See bnToMPI for details of the format
mpiToBN :: BS.ByteString -> IO BigNum
View
@@ -24,7 +24,7 @@ import Data.IORef
import Foreign
import Foreign.C.Types
import qualified Data.ByteString as BS
-import qualified Data.ByteString.Base as BSB
+import qualified Data.ByteString.Internal as BSI
import OpenSSL.Utils
data Mode = Encrypt | Decrypt deriving (Eq, Show)
@@ -94,7 +94,7 @@ aesCBC (AESCtx ctx iv _ _ mode) input = do
withForeignPtr ctx $ \ctxPtr ->
withForeignPtr iv $ \ivPtr ->
BS.useAsCStringLen input $ \(ptr, len) ->
- BSB.create (BS.length input) $ \out ->
+ BSI.create (BS.length input) $ \out ->
_AES_cbc_encrypt ptr out (fromIntegral len) ctxPtr ivPtr $ modeToInt mode
-- | Encrypt some number of bytes using CTR mode. This is an IO function
@@ -107,7 +107,7 @@ aesCTR (AESCtx ctx iv ecounter nref Encrypt) input = do
withForeignPtr iv $ \ivPtr ->
withForeignPtr ecounter $ \ecptr ->
BS.useAsCStringLen input $ \(ptr, len) ->
- BSB.create (BS.length input) $ \out ->
+ BSI.create (BS.length input) $ \out ->
alloca $ \nptr -> do
n <- readIORef nref
poke nptr n
@@ -16,7 +16,9 @@ module OpenSSL.EVP.Base64
where
import Control.Exception
-import Data.ByteString.Base
+import Data.ByteString.Internal (createAndTrim)
+import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
+import qualified Data.ByteString.Lazy.Internal as L8Internal
import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Lazy.Char8 as L8
import Data.List
@@ -29,13 +31,13 @@ import Foreign.C
-- な最大の 3 の倍數の位置で分割し、殘りは次のブロックの一部と見做す。
--
-- デコード時: 分割のアルゴリズムは同じだが最低バイト数が 4。
-nextBlock :: Int -> ([ByteString], LazyByteString) -> ([ByteString], LazyByteString)
-nextBlock _ (xs, LPS [] ) = (xs, LPS [])
-nextBlock minLen (xs, LPS src) = if foldl' (+) 0 (map B8.length xs) >= minLen then
- (xs, LPS src)
- else
- case src of
- (y:ys) -> nextBlock minLen (xs ++ [y], LPS ys)
+nextBlock :: Int -> ([B8.ByteString], L8.ByteString) -> ([B8.ByteString], L8.ByteString)
+nextBlock _ (xs, L8Internal.Empty ) = (xs, L8Internal.Empty)
+nextBlock minLen (xs, src) = if foldl' (+) 0 (map B8.length xs) >= minLen then
+ (xs, src)
+ else
+ case src of
+ L8Internal.Chunk y ys -> nextBlock minLen (xs ++ [y], ys)
{- encode -------------------------------------------------------------------- -}
@@ -44,7 +46,7 @@ foreign import ccall unsafe "EVP_EncodeBlock"
_EncodeBlock :: Ptr CChar -> Ptr CChar -> Int -> IO Int
-encodeBlock :: ByteString -> ByteString
+encodeBlock :: B8.ByteString -> B8.ByteString
encodeBlock inBS
= unsafePerformIO $
unsafeUseAsCStringLen inBS $ \ (inBuf, inLen) ->
@@ -63,12 +65,12 @@ encodeBase64 :: String -> String
encodeBase64 = L8.unpack . encodeBase64LBS . L8.pack
-- |@'encodeBase64BS' bs@ strictly encodes a chunk of data to Base64.
-encodeBase64BS :: ByteString -> ByteString
+encodeBase64BS :: B8.ByteString -> B8.ByteString
encodeBase64BS = encodeBlock
-- |@'encodeBase64LBS' lbs@ lazilly encodes a stream of data to
-- Base64. The string doesn't have to be finite.
-encodeBase64LBS :: LazyByteString -> LazyByteString
+encodeBase64LBS :: L8.ByteString -> L8.ByteString
encodeBase64LBS inLBS
| L8.null inLBS = L8.empty
| otherwise
@@ -83,12 +85,11 @@ encodeBase64LBS inLBS
remain = if B8.null leftover then
remain'
else
- case remain' of
- LPS xs -> LPS (leftover:xs)
+ L8.fromChunks [leftover] `L8.append` remain'
encodedBlock = encodeBlock block
- LPS encodedRemain = encodeBase64LBS remain
+ encodedRemain = encodeBase64LBS remain
in
- LPS ([encodedBlock] ++ encodedRemain)
+ L8.fromChunks [encodedBlock] `L8.append` encodedRemain
{- decode -------------------------------------------------------------------- -}
@@ -97,7 +98,7 @@ foreign import ccall unsafe "EVP_DecodeBlock"
_DecodeBlock :: Ptr CChar -> Ptr CChar -> Int -> IO Int
-decodeBlock :: ByteString -> ByteString
+decodeBlock :: B8.ByteString -> B8.ByteString
decodeBlock inBS
= assert (B8.length inBS `mod` 4 == 0) $
unsafePerformIO $
@@ -112,12 +113,12 @@ decodeBase64 = L8.unpack . decodeBase64LBS . L8.pack
-- |@'decodeBase64BS' bs@ strictly decodes a chunk of data from
-- Base64.
-decodeBase64BS :: ByteString -> ByteString
+decodeBase64BS :: B8.ByteString -> B8.ByteString
decodeBase64BS = decodeBlock
-- |@'decodeBase64LBS' lbs@ lazilly decodes a stream of data from
-- Base64. The string doesn't have to be finite.
-decodeBase64LBS :: LazyByteString -> LazyByteString
+decodeBase64LBS :: L8.ByteString -> L8.ByteString
decodeBase64LBS inLBS
| L8.null inLBS = L8.empty
| otherwise
@@ -129,9 +130,8 @@ decodeBase64LBS inLBS
remain = if B8.null leftover then
remain'
else
- case remain' of
- LPS xs -> LPS (leftover:xs)
+ L8.fromChunks [leftover] `L8.append` remain'
decodedBlock = decodeBlock block
- LPS decodedRemain = decodeBase64LBS remain
+ decodedRemain = decodeBase64LBS remain
in
- LPS ([decodedBlock] ++ decodedRemain)
+ L8.fromChunks [decodedBlock] `L8.append` decodedRemain
Oops, something went wrong. Retry.

0 comments on commit e75a99a

Please sign in to comment.