Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for crypto-api 0.9 while keeping support for old versions.

  • Loading branch information...
commit 3abc45a5dc9dc818aa736643dc3b47fd7904cea8 1 parent 83fa50b
@meteficha meteficha authored
Showing with 24 additions and 10 deletions.
  1. +15 −7 crypto-conduit.cabal
  2. +8 −2 src/Crypto/Conduit.hs
  3. +1 −1  tests/runtests.hs
View
22 crypto-conduit.cabal
@@ -23,6 +23,10 @@ Source-repository head
Type: git
Location: git://github.com/meteficha/crypto-conduit.git
+Flag old-crypto-api
+ Description: Use crypto-api < 0.9.
+ Default: False
+
Library
Hs-Source-Dirs: src
Exposed-modules:
@@ -31,20 +35,24 @@ Library
base >= 3 && < 5,
bytestring >= 0.9 && < 0.10,
cereal >= 0.3 && < 0.4,
- crypto-api >= 0.8 && < 0.9,
conduit >= 0.2 && < 0.3,
transformers == 0.2.*
+ if flag(old-crypto-api)
+ Build-depends: crypto-api >= 0.8 && < 0.9
+ GHC-options: -DOLD_CRYPTO_API
+ else
+ Build-depends: crypto-api >= 0.9 && < 0.10
GHC-options: -Wall
Test-suite runtests
Type: exitcode-stdio-1.0
Build-depends:
- base >= 3 && < 5,
- bytestring >= 0.9 && < 0.10,
- cereal >= 0.3 && < 0.4,
- crypto-api >= 0.8 && < 0.9,
- conduit >= 0.2 && < 0.3,
- transformers == 0.2.*,
+ base,
+ bytestring,
+ cereal,
+ crypto-api >= 0.9,
+ conduit,
+ transformers,
cryptocipher == 0.3.*,
cryptohash == 0.7.*,
View
10 src/Crypto/Conduit.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE BangPatterns #-}
+{-# LANGUAGE BangPatterns, CPP #-}
-- | This module contains wrappers for cryptographic functions
-- using the @conduit@ package. Currently there is support for
-- hashes, HMACs and many modes of block ciphers (but not
@@ -110,7 +110,13 @@ hashFile fp = liftIO $ runResourceT (sourceFile fp $$ sinkHash)
-- | A 'Sink' that computes the HMAC of a stream of
-- 'B.ByteString'@s@ and creates a digest @d@.
-sinkHmac :: (Resource m, C.Hash ctx d) => C.MacKey -> Sink B.ByteString m d
+sinkHmac :: (Resource m, C.Hash ctx d) =>
+#if OLD_CRYPTO_API
+ C.MacKey
+#else
+ C.MacKey ctx d
+#endif
+ -> Sink B.ByteString m d
sinkHmac (C.MacKey key) = blocked AnyMultiple blockSize =$ sink
where
--------- Taken and modified from Crypto.HMAC:
View
2  tests/runtests.hs
@@ -103,7 +103,7 @@ prop_sinkHash d input =
in d1 == d2
-prop_sinkHmac :: C.Hash ctx d => d -> C.MacKey -> L.ByteString -> Bool
+prop_sinkHmac :: C.Hash ctx d => d -> C.MacKey ctx d -> L.ByteString -> Bool
prop_sinkHmac d mackey input =
let d1 = runPureResource $ sourceList (L.toChunks input) $$ sinkHmac mackey
d2 = C.hmac mackey input `asTypeOf` d

0 comments on commit 3abc45a

Please sign in to comment.
Something went wrong with that request. Please try again.