module Data.UUID.Named
(generateNamed
,namespaceDNS
,namespaceURL
,namespaceOID
,namespaceX500
) where
import Data.UUID.Internal
import Control.Applicative ((<*>),(<$>))
import Data.Binary.Get (runGet, getWord32be)
import Data.Maybe
import Data.Word (Word8)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
generateNamed :: (B.ByteString -> B.ByteString)
-> Word8
-> UUID
-> [Word8]
-> UUID
generateNamed hash version namespace object =
let chunk = B.pack $ toList namespace ++ object
bytes = BL.fromChunks . (:[]) $ hash chunk
w = getWord32be
unpackBytes = runGet $
buildFromWords version <$> w <*> w <*> w <*> w
in unpackBytes bytes
unsafeFromString :: String -> UUID
unsafeFromString = fromJust . fromString
namespaceDNS :: UUID
namespaceDNS = unsafeFromString "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
namespaceURL :: UUID
namespaceURL = unsafeFromString "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
namespaceOID :: UUID
namespaceOID = unsafeFromString "6ba7b812-9dad-11d1-80b4-00c04fd430c8"
namespaceX500 :: UUID
namespaceX500 = unsafeFromString "6ba7b814-9dad-11d1-80b4-00c04fd430c8"