on 8917b68 help sign in
67 lines 1.7 kB history raw
1-- |
2-- Module : Data.UUID.Named
3-- Copyright : (c) 2008 Antoine Latter
4--
5-- License : BSD-style
6--
7-- Maintainer : aslatter@gmail.com
8-- Stability : experimental
9-- Portability : portable
10--
11--
12-- This module implements Version 3/5 UUIDs as specified
13-- in RFC 4122.
14--
15-- These UUIDs identify an object within a namespace,
16-- and are deterministic.
17--
18-- The namespace is identified by a UUID. Several sample
19-- namespaces are enclosed.
21module Data.UUID.Named
22 (generateNamed
23 ,namespaceDNS
24 ,namespaceURL
25 ,namespaceOID
26 ,namespaceX500
27 ) where
29import Data.UUID.Internal
31import Data.Binary
32import Data.Maybe
34import qualified Data.ByteString.Lazy as BS
36-- |Generate a 'UUID' within the specified namespace out of the given
37-- object.
38generateNamed :: ([Word8] -> (Word32, Word32, Word32, Word32)) -- ^Hash
39 -> Word8 -- ^Version
40 -> UUID -- ^Namespace
41 -> [Word8] -- ^Object
42 -> UUID
43generateNamed hash version namespace object =
44 let chunk = BS.unpack (toByteString namespace) ++ object
45 (w1, w2, w3, w4) = hash chunk
46 in buildFromWords version w1 w2 w3 w4
50unsafeFromString :: String -> UUID
51unsafeFromString = fromJust . fromString
53-- |The namespace for DNS addresses
54namespaceDNS :: UUID
55namespaceDNS = unsafeFromString "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
57-- |The namespace for URLs
58namespaceURL :: UUID
59namespaceURL = unsafeFromString "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
61-- |The namespace for ISO OIDs
62namespaceOID :: UUID
63namespaceOID = unsafeFromString "6ba7b812-9dad-11d1-80b4-00c04fd430c8"
65-- |The namespace for X.500 DNs
66namespaceX500 :: UUID
67namespaceX500 = unsafeFromString "6ba7b814-9dad-11d1-80b4-00c04fd430c8"