@@ -27,10 +27,12 @@ module Data.UUID.V5
2727 ) where
2828
2929import Data.Word
30+import Data.Bits
31+import qualified Data.ByteString as B
3032
3133import Data.UUID.Internal
3234import qualified Data.UUID.Named as Shared
33−import qualified Data.Digest.SHA1 as SHA1
35+import qualified Crypto.Hash.SHA1 as SHA1
3436
3537
3638-- |Generate a 'UUID' within the specified namespace out of the given
@@ -43,5 +45,17 @@ generateNamed :: UUID -- ^Namespace
4345 -> UUID
4446generateNamed = Shared.generateNamed hash 5
4547 where hash bytes
46− = case SHA1.hash bytes of
47− SHA1.Word160 w1 w2 w3 w4 _w5 -> (w1, w2, w3, w4)
48+ = case B.unpack $ SHA1.hash $ B.pack bytes of
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