2-- Module : Data.UUID.V5
3-- Copyright : (c) 2008 Antoine Latter
7-- Maintainer : aslatter@gmail.com
8-- Stability : experimental
9-- Portability : portable
12-- This module implements Version 5 UUIDs as specified
15-- These UUIDs identify an object within a namespace,
16-- and are deterministic.
18-- The namespace is identified by a UUID. Several sample
19-- namespaces are enclosed.
30import Data.UUID.Internal
36import qualified Data.ByteString.Lazy as BS
37import Data.ByteString.Lazy (ByteString)
39import qualified Data.Digest.SHA1 as SHA1
42-- |Generate a 'UUID' within the specified namespace out of the given
46generateNamed :: UUID -- ^Namespace
49generateNamed namespace object =
50 let chunk = BS.unpack (encode namespace) ++ object
51 SHA1.Word160 w1 w2 w3 w4 w5 = SHA1.hash chunk
55 th = (versionSHA .|.) $ (versionMask .&.) $ low16 w2
56 ch = (reserved .|.) $ (reservedMask .&.) $ high8 $ high16 w3
58 node = Node (high8 (low16 w3))
64 in UUID tl tm th ch cl node
72low16 :: Word32 -> Word16
73low16 = fromIntegral . (.&. 0x0000FFFF)
75high16 :: Word32 -> Word16
76high16 = fromIntegral . flip shiftR 16
78low8 :: Word16 -> Word8
79low8 = fromIntegral . (.&. 0x00FF)
81high8 :: Word16 -> Word8
82high8 = fromIntegral . flip shiftR 8
84versionSHA = 5 `shiftL` 12
86unsafeFromString :: String -> UUID
87unsafeFromString = fromJust . fromString
89-- |The namespace for DNS addresses
91namespaceDNS = unsafeFromString "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
93-- |The namespace for URLs
95namespaceURL = unsafeFromString "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
98namespaceOID = unsafeFromString "6ba7b812-9dad-11d1-80b4-00c04fd430c8"
101namespaceX500 = unsafeFromString "6ba7b814-9dad-11d1-80b4-00c04fd430c8"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list