Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Thomas M. DuBuisson authored

Showing 3 changed files with 10 additions and 3 deletions. Show diff stats Hide diff stats

  1. +3 2 Data/Digest/Pure/MD5.hs
  2. +6 0 Test/MD5.hs
  3. +1 1  pureMD5.cabal
5 Data/Digest/Pure/MD5.hs
@@ -85,7 +85,7 @@ h3 = 0x10325476
85 85 -- | Processes a lazy ByteString and returns the md5 digest.
86 86 -- This is probably what you want.
87 87 md5 :: L.ByteString -> MD5Digest
88   -md5 = hash
  88 +md5 = flip md5Finalize B.empty . foldl' md5Update md5InitialContext . L.toChunks -- hash
89 89
90 90 -- | Closes an MD5 context, thus producing the digest.
91 91 md5Finalize :: MD5Context -> B.ByteString -> MD5Digest
@@ -95,8 +95,9 @@ md5Finalize !ctx@(MD5Ctx (MD5Par a b c d) remPrev !totLen) end =
95 95 putWord8 0x80
96 96 mapM_ putWord8 (replicate lenZeroPad 0)
97 97 putWord64le totLen' )
98   - in MD5Digest $ mdPartial $ md5Update ctx (B.concat padBS)
  98 + in MD5Digest $ mdPartial $ md5Update ctx' (B.concat padBS)
99 99 where
  100 + ctx' = md5Update ctx rem
100 101 rem = B.append remPrev end
101 102 l = B.length rem
102 103 lenZeroPad = if (l + 1) <= blockSizeBytes - 8
6 Test/MD5.hs
@@ -2,6 +2,7 @@
2 2 module Test.MD5 where
3 3
4 4 import Test.QuickCheck
  5 +import Test.Crypto
5 6 import Data.Digest.Pure.MD5
6 7 import qualified Data.ByteString.Lazy as L
7 8 import qualified Data.ByteString as S
@@ -9,6 +10,10 @@ import Control.Monad (forM)
9 10 import Data.Word (Word8)
10 11 import Data.Binary
11 12
  13 +test = runTests (makeMD5Tests (undefined :: MD5Digest))
  14 +
  15 +{-
  16 +
12 17 instance Arbitrary Word8 where
13 18 arbitrary = (arbitrary :: Gen Int) >>= return . fromIntegral
14 19
@@ -68,3 +73,4 @@ runTest (T a s) = do
68 73 quickCheck a
69 74
70 75 runTests = mapM_ runTest tests
  76 +-}
2  pureMD5.cabal
@@ -14,7 +14,7 @@ tested-with: GHC == 6.10.1
14 14 extra-source-files: Test/MD5.hs Test/md5test.hs
15 15
16 16 Library
17   - 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
  17 + 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
18 18 ghc-options: -O2 -funfolding-use-threshold66 -funfolding-creation-threshold66 -fexcess-precision -funbox-strict-fields
19 19 hs-source-dirs:
20 20 exposed-modules: Data.Digest.Pure.MD5

0 comments on commit 34cc0c4

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