use md5 from cryptohash package instead of nano-md5 to remove dependency on OpenSSL

This commit is contained in:
Tony Hannan 2011-03-11 11:11:14 -05:00
parent a1b47687e8
commit db58a9c4ca
2 changed files with 16 additions and 5 deletions

View file

@ -32,14 +32,17 @@ import Data.Int
import Data.Bits import Data.Bits
import Data.IORef import Data.IORef
import System.IO.Unsafe (unsafePerformIO) import System.IO.Unsafe (unsafePerformIO)
import Data.Digest.OpenSSL.MD5 (md5sum) import qualified Crypto.Hash.MD5 as MD5 (hash)
import Data.UString as U (pack, append, toByteString) import Data.UString as U (pack, append, toByteString)
import qualified Data.ByteString as BS (ByteString, unpack)
import Data.Word (Word8)
import System.IO.Error as E (try) import System.IO.Error as E (try)
import Control.Monad.Error import Control.Monad.Error
import Control.Monad.Util (whenJust) import Control.Monad.Util (whenJust)
import Network.Abstract hiding (send) import Network.Abstract hiding (send)
import System.IO (hFlush) import System.IO (hFlush)
import Database.MongoDB.Internal.Util (hGetN, bitOr) import Database.MongoDB.Internal.Util (hGetN, bitOr)
import Numeric (showHex)
-- Network -> Server -> (Sink, Source) -- Network -> Server -> (Sink, Source)
-- (Sink, Source) -> Pipeline -- (Sink, Source) -> Pipeline
@ -306,7 +309,15 @@ type Password = UString
type Nonce = UString type Nonce = UString
pwHash :: Username -> Password -> UString pwHash :: Username -> Password -> UString
pwHash u p = pack . md5sum . toByteString $ u `U.append` ":mongo:" `U.append` p pwHash u p = pack . byteStringHex . MD5.hash . toByteString $ u `U.append` ":mongo:" `U.append` p
pwKey :: Nonce -> Username -> Password -> UString pwKey :: Nonce -> Username -> Password -> UString
pwKey n u p = pack . md5sum . toByteString . U.append n . U.append u $ pwHash u p pwKey n u p = pack . byteStringHex . MD5.hash . toByteString . U.append n . U.append u $ pwHash u p
byteStringHex :: BS.ByteString -> String
-- ^ Hexadecimal string representation of a byte string. Each byte yields two hexadecimal characters.
byteStringHex = concatMap byteHex . BS.unpack
byteHex :: Word8 -> String
-- ^ Two char hexadecimal representation of byte
byteHex b = (if b < 16 then ('0' :) else id) (showHex b "")

View file

@ -1,5 +1,5 @@
name: mongoDB name: mongoDB
version: 0.9.4 version: 0.9.5
build-type: Simple build-type: Simple
license: OtherLicense license: OtherLicense
license-file: LICENSE license-file: LICENSE
@ -13,7 +13,7 @@ build-depends:
bytestring -any, bytestring -any,
containers -any, containers -any,
mtl >= 2, mtl >= 2,
nano-md5 -any, cryptohash -any,
network -any, network -any,
parsec -any, parsec -any,
random -any random -any