cryptonite-conduit 0.1 → 0.2.0
raw patch · 4 files changed
+87/−6 lines, 4 filesdep +conduit-combinatorsdep +cryptonite-conduitdep +memorydep ~basePVP ok
version bump matches the API change (PVP)
Dependencies added: conduit-combinators, cryptonite-conduit, memory, tasty, tasty-hunit
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Crypto.MAC.HMAC.Conduit: sinkHMAC :: (Monad m, ByteArrayAccess key, HashAlgorithm hash) => key -> ConduitM ByteString o m (HMAC hash)
Files
- Crypto/MAC/HMAC/Conduit.hs +30/−0
- README.md +9/−2
- cryptonite-conduit.cabal +21/−4
- test/Spec.hs +27/−0
+ Crypto/MAC/HMAC/Conduit.hs view
@@ -0,0 +1,30 @@+{-# LANGUAGE RankNTypes, BangPatterns #-}+-- |+-- Module : Crypto.MAC.HMAC.Conduit+-- License : BSD-style+-- Maintainer : Vincent Hanquez <vincent@snarc.org>+-- Stability : experimental+-- Portability : unknown+--+-- A module containing Conduit facilities for hmac based functions.+--+module Crypto.MAC.HMAC.Conduit+ ( -- * Cryptographic hash functions+ sinkHMAC+ ) where++import Crypto.Hash+import Crypto.MAC.HMAC+import Data.ByteArray+import Data.Conduit+import qualified Data.ByteString as BS++-- | A 'Sink' that calculates HMAC of a stream of 'B.ByteString'@s@ and+-- returns digest @d@.+sinkHMAC :: (Monad m, ByteArrayAccess key, HashAlgorithm hash) => key -> ConduitM BS.ByteString o m (HMAC hash)+sinkHMAC key = sink (initialize key)+ where sink ctx = do+ b <- await+ case b of+ Nothing -> return $! finalize ctx+ Just bs -> sink $! update ctx bs
README.md view
@@ -1,4 +1,11 @@-cryptohash-conduit+cryptonite-conduit ================== -Documentation: [cryptohash-conduit on hackage](http://hackage.haskell.org/package/cryptohash-conduit)+[](https://gitter.im/vincenthz/cryptonite?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)+[](https://travis-ci.org/haskell-crypto/cryptonite-conduit)+[](http://en.wikipedia.org/wiki/BSD_licenses)+[](http://haskell.org)++Documentation: [cryptonite-conduit on hackage](http://hackage.haskell.org/package/cryptonite-conduit)++Simple conduit wrapper for cryptonite hashes, and maybe further construction as needed
cryptonite-conduit.cabal view
@@ -1,10 +1,10 @@ Name: cryptonite-conduit-Version: 0.1+Version: 0.2.0 Synopsis: cryptonite conduit Description: Conduit bridge for cryptonite .- For now only provide a conduit version for hash, but+ For now only provide a conduit version for hash and hmac, but with contribution, this could provide cipher conduits too, and probably other things. License: BSD3@@ -20,15 +20,32 @@ Extra-source-files: README.md Library- Exposed-modules: Crypto.Hash.Conduit+ Exposed-modules: Crypto.MAC.HMAC.Conduit+ Crypto.Hash.Conduit Build-depends: base >= 4 && < 5 , bytestring , conduit- , resourcet , conduit-extra , cryptonite+ , memory+ , resourcet , transformers ghc-options: -Wall -fwarn-tabs++test-suite cryptonite-conduit-test+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: Spec.hs+ build-depends: base+ , bytestring+ , conduit+ , conduit-combinators+ , cryptonite+ , cryptonite-conduit+ , memory+ , tasty+ , tasty-hunit+ ghc-options: -threaded -rtsopts -with-rtsopts=-N -W -Wall source-repository head type: git
+ test/Spec.hs view
@@ -0,0 +1,27 @@+{-# Language OverloadedStrings #-}+import Conduit+import Crypto.Hash+import Crypto.MAC.HMAC+import Crypto.MAC.HMAC.Conduit+import Data.ByteArray.Encoding+import Test.Tasty+import Test.Tasty.HUnit+import qualified Data.ByteString as BS+import qualified Data.ByteString.Lazy as BL++main :: IO ()+main = defaultMain tests++tests :: TestTree+tests = testGroup "Cryptonite conduit tests"+ [ testGroup "HMAC"+ [ testCase "File HMAC is correct" testFileHMAC+ ]+ ]++testFileHMAC :: Assertion+testFileHMAC = do+ let source = BL.take (1024 * 1024 * 3 + 150) $ BL.iterate (+ 1) 0+ testhmac <- runConduit $ sourceLazy source $$ sinkHMAC ("foobar" :: BS.ByteString)+ let hexdump = convertToBase Base16 (testhmac :: HMAC SHA512t_256)+ assertEqual "HMAC mismatch" "ab78ef7a3a7b02b2ef50ee1a17e43ae0c134e0bece468b047780626264301831" (hexdump :: BS.ByteString)