on master help sign in
Use cryptohash instead of Crypto
e24d8b2Bas van Dijk
Data/UUID/V3.hs+3−2
@@ -28,10 +28,11 @@ module Data.UUID.V3
28
28
29import Data.Word
29import Data.Word
30import Data.Bits
30import Data.Bits
31+import qualified Data.ByteString as B
31
32
32import Data.UUID.Internal
33import Data.UUID.Internal
33import qualified Data.UUID.Named as Shared
34import qualified Data.UUID.Named as Shared
34−import qualified Data.Digest.MD5 as MD5
35+import qualified Crypto.Hash.MD5 as MD5
35
36
36
37
37-- |Generate a 'UUID' within the specified namespace out of the given
38-- |Generate a 'UUID' within the specified namespace out of the given
@@ -46,7 +47,7 @@ generateNamed = Shared.generateNamed hash 3
46
47
47hash :: [Word8] -> (Word32, Word32, Word32, Word32)
48hash :: [Word8] -> (Word32, Word32, Word32, Word32)
48hash bytes
49hash bytes
49− = case map f $ chunk 4 $ MD5.hash bytes of
50+ = case map f $ chunk 4 $ B.unpack $ MD5.hash $ B.pack bytes of
50 w1:w2:w3:w4:_ -> (w1, w2, w3, w4)
51 w1:w2:w3:w4:_ -> (w1, w2, w3, w4)
51 _ -> error "Data.UUID.V3.hash: fatal error"
52 _ -> error "Data.UUID.V3.hash: fatal error"
52
53
Data/UUID/V5.hs+17−3
@@ -27,10 +27,12 @@ module Data.UUID.V5
27 ) where
27 ) where
28
28
29import Data.Word
29import Data.Word
30+import Data.Bits
31+import qualified Data.ByteString as B
30
32
31import Data.UUID.Internal
33import Data.UUID.Internal
32import qualified Data.UUID.Named as Shared
34import qualified Data.UUID.Named as Shared
33−import qualified Data.Digest.SHA1 as SHA1
35+import qualified Crypto.Hash.SHA1 as SHA1
34
36
35
37
36-- |Generate a 'UUID' within the specified namespace out of the given
38-- |Generate a 'UUID' within the specified namespace out of the given
@@ -43,5 +45,17 @@ generateNamed :: UUID -- ^Namespace
43 -> UUID
45 -> UUID
44generateNamed = Shared.generateNamed hash 5
46generateNamed = Shared.generateNamed hash 5
45 where hash bytes
47 where hash bytes
46− = case SHA1.hash bytes of
48+ = case B.unpack $ SHA1.hash $ B.pack bytes of
47− SHA1.Word160 w1 w2 w3 w4 _w5 -> (w1, w2, w3, w4)
49+ a1:b1:c1:d1: a2:b2:c2:d2: a3:b3:c3:d3: a4:b4:c4:d4:_ ->
50+ ( toWord a1 b1 c1 d1
51+ , toWord a2 b2 c2 d2
52+ , toWord a3 b3 c3 d3
53+ , toWord a4 b4 c4 d4
54+ )
55+ _ -> error "Data.UUID.V5.hash: fatal error"
56+
57+toWord :: Word8 -> Word8 -> Word8 -> Word8 -> Word32
58+toWord a b c d = fromIntegral a `shiftL` 24
59+ .|. fromIntegral b `shiftL` 16
60+ .|. fromIntegral c `shiftL` 8
61+ .|. fromIntegral d
uuid.cabal+2−2
@@ -13,7 +13,7 @@ Cabal-Version: >= 1.8
13Description:
13Description:
14 This library is useful for creating, comparing, parsing and
14 This library is useful for creating, comparing, parsing and
15 printing Universally Unique Identifiers.
15 printing Universally Unique Identifiers.
16− See <http://en.wikipedia.org/wiki/UUID> for the general idea.
16+ See <http://en.wikipedia.org/wiki/UUID> for the general idea.
17
17
18Synopsis: For creating, comparing, parsing and printing Universally Unique Identifiers
18Synopsis: For creating, comparing, parsing and printing Universally Unique Identifiers
19
19
@@ -26,7 +26,7 @@ Extra-Source-Files:
26
26
27
27
28Library
28Library
29− Build-Depends: random, binary, bytestring, Crypto, maccatcher,
29+ Build-Depends: random, binary, bytestring, cryptohash, maccatcher,
30 time, base >=3, base < 5
30 time, base >=3, base < 5
31
31
32 Exposed-Modules:
32 Exposed-Modules: