Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix context of finalize, fix .cabal, use crypto-api tests.

Ignore-this: d4607ce88998142ca2f08e62a8544933

darcs-hash:20100816012343-cef97-56e8d2c571fb60c97cfa87b186097fadb10de15e.gz
  • Loading branch information...
commit 34cc0c43bed834ae18f9d29d3ac6c5257b13a849 1 parent b576e2d
@TomMD authored
Showing with 10 additions and 3 deletions.
  1. +3 −2 Data/Digest/Pure/MD5.hs
  2. +6 −0 Test/MD5.hs
  3. +1 −1  pureMD5.cabal
View
5 Data/Digest/Pure/MD5.hs
@@ -85,7 +85,7 @@ h3 = 0x10325476
-- | Processes a lazy ByteString and returns the md5 digest.
-- This is probably what you want.
md5 :: L.ByteString -> MD5Digest
-md5 = hash
+md5 = flip md5Finalize B.empty . foldl' md5Update md5InitialContext . L.toChunks -- hash
-- | Closes an MD5 context, thus producing the digest.
md5Finalize :: MD5Context -> B.ByteString -> MD5Digest
@@ -95,8 +95,9 @@ md5Finalize !ctx@(MD5Ctx (MD5Par a b c d) remPrev !totLen) end =
putWord8 0x80
mapM_ putWord8 (replicate lenZeroPad 0)
putWord64le totLen' )
- in MD5Digest $ mdPartial $ md5Update ctx (B.concat padBS)
+ in MD5Digest $ mdPartial $ md5Update ctx' (B.concat padBS)
where
+ ctx' = md5Update ctx rem
rem = B.append remPrev end
l = B.length rem
lenZeroPad = if (l + 1) <= blockSizeBytes - 8
View
6 Test/MD5.hs
@@ -2,6 +2,7 @@
module Test.MD5 where
import Test.QuickCheck
+import Test.Crypto
import Data.Digest.Pure.MD5
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString as S
@@ -9,6 +10,10 @@ import Control.Monad (forM)
import Data.Word (Word8)
import Data.Binary
+test = runTests (makeMD5Tests (undefined :: MD5Digest))
+
+{-
+
instance Arbitrary Word8 where
arbitrary = (arbitrary :: Gen Int) >>= return . fromIntegral
@@ -68,3 +73,4 @@ runTest (T a s) = do
quickCheck a
runTests = mapM_ runTest tests
+-}
View
2  pureMD5.cabal
@@ -14,7 +14,7 @@ tested-with: GHC == 6.10.1
extra-source-files: Test/MD5.hs Test/md5test.hs
Library
- Build-Depends: base == 4.*, bytestring >= 0.9 && < 0.10, binary >= 0.4.0 && < 0.6.0, cereal >= 0.2, crypto >= 0.0.0.1, tagged
+ Build-Depends: base == 4.*, bytestring >= 0.9 && < 0.10, binary >= 0.4.0 && < 0.6.0, cereal >= 0.2, crypto-api >= 0.0.0.1, tagged
ghc-options: -O2 -funfolding-use-threshold66 -funfolding-creation-threshold66 -fexcess-precision -funbox-strict-fields
hs-source-dirs:
exposed-modules: Data.Digest.Pure.MD5
Please sign in to comment.
Something went wrong with that request. Please try again.