module Data.UUID.Named
(generateNamed
,namespaceDNS
,namespaceURL
,namespaceOID
,namespaceX500
) where
import Data.UUID.Types.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 :: (ByteString -> ByteString) -> Word8 -> UUID -> [Word8] -> UUID
generateNamed ByteString -> ByteString
hash Word8
version UUID
namespace [Word8]
object =
let chunk :: ByteString
chunk = [Word8] -> ByteString
B.pack ([Word8] -> ByteString) -> [Word8] -> ByteString
forall a b. (a -> b) -> a -> b
$ UUID -> [Word8]
toList UUID
namespace [Word8] -> [Word8] -> [Word8]
forall a. [a] -> [a] -> [a]
++ [Word8]
object
bytes :: ByteString
bytes = [ByteString] -> ByteString
BL.fromChunks ([ByteString] -> ByteString)
-> (ByteString -> [ByteString]) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:[]) (ByteString -> ByteString) -> ByteString -> ByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
hash ByteString
chunk
w :: Get Word32
w = Get Word32
getWord32be
unpackBytes :: ByteString -> UUID
unpackBytes = Get UUID -> ByteString -> UUID
forall a. Get a -> ByteString -> a
runGet (Get UUID -> ByteString -> UUID) -> Get UUID -> ByteString -> UUID
forall a b. (a -> b) -> a -> b
$
Word8 -> Word32 -> Word32 -> Word32 -> Word32 -> UUID
buildFromWords Word8
version (Word32 -> Word32 -> Word32 -> Word32 -> UUID)
-> Get Word32 -> Get (Word32 -> Word32 -> Word32 -> UUID)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Word32
w Get (Word32 -> Word32 -> Word32 -> UUID)
-> Get Word32 -> Get (Word32 -> Word32 -> UUID)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Word32
w Get (Word32 -> Word32 -> UUID)
-> Get Word32 -> Get (Word32 -> UUID)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Word32
w Get (Word32 -> UUID) -> Get Word32 -> Get UUID
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Word32
w
in ByteString -> UUID
unpackBytes ByteString
bytes
unsafeFromString :: String -> UUID
unsafeFromString :: String -> UUID
unsafeFromString = Maybe UUID -> UUID
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe UUID -> UUID) -> (String -> Maybe UUID) -> String -> UUID
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe UUID
fromString
namespaceDNS :: UUID
namespaceDNS :: UUID
namespaceDNS = String -> UUID
unsafeFromString String
"6ba7b810-9dad-11d1-80b4-00c04fd430c8"
namespaceURL :: UUID
namespaceURL :: UUID
namespaceURL = String -> UUID
unsafeFromString String
"6ba7b811-9dad-11d1-80b4-00c04fd430c8"
namespaceOID :: UUID
namespaceOID :: UUID
namespaceOID = String -> UUID
unsafeFromString String
"6ba7b812-9dad-11d1-80b4-00c04fd430c8"
namespaceX500 :: UUID
namespaceX500 :: UUID
namespaceX500 = String -> UUID
unsafeFromString String
"6ba7b814-9dad-11d1-80b4-00c04fd430c8"