packages feed

uuid 1.2.5 → 1.2.6

raw patch · 7 files changed

+151/−65 lines, 7 filesdep ~random

Dependency ranges changed: random

Files

CHANGES view
@@ -1,3 +1,15 @@+1.2.6++- Add module 'V4' to direct attention to our Random instance++- In module 'V1' seed the generator with a random number+  if the hardware MAC address could not be discovered.++- Fix and cleanup various haddocks.++- In module docs, warn about MD5 use in Data.UUID.V3 and+  encourage the reader to use Data.UUID.V5 instead.+ 1.2.5  - Use 'cryptohash' package for MD5 and SHA1 instead of 'Crypto'
Data/UUID.hs view
@@ -1,21 +1,28 @@--- |--- Module      : Data.UUID--- Copyright   : (c) 2008 Antoine Latter------ License     : BSD-style------ Maintainer  : aslatter@gmail.com--- Stability   : experimental--- Portability : portable--- --- --- This library is useful for comparing, parsing and--- printing Universally Unique Identifiers.--- See <http://en.wikipedia.org/wiki/UUID> for the general idea.--- See <http://tools.ietf.org/html/rfc4122> for the specification.------ For generating UUIDs, check out 'Data.UUID.V1', 'Data.UUID.V5' and--- 'System.Random'.+{- |+Module      : Data.UUID+Copyright   : (c) 2008,2012 Antoine Latter++License     : BSD-style++Maintainer  : aslatter@gmail.com+Stability   : experimental+Portability : portable+++This library is useful for comparing, parsing and+printing Universally Unique Identifiers.+See <http://en.wikipedia.org/wiki/UUID> for the general idea.+See <http://tools.ietf.org/html/rfc4122> for the specification.++* Random UUIDs may be generated using 'Data.UUID.V4.nextRandom' or+your favorite instance of 'System.Random.Random'.++* We have an implementation of generating a UUID from the hardware+MAC address and current system time in "Data.UUID.V1".++* For name-based generation of UUIDs using SHA-1 hashing see+"Data.UUID.V5".+-}  module Data.UUID(UUID                 ,toString
Data/UUID/Internal.hs view
@@ -77,12 +77,15 @@  -- | Covert a 'UUID' into a sequence of 'Word32' values. -- Usefull for when you need to serialize a UUID and--- neither 'Storable' nor 'Binary' are appropriate. +-- neither 'Storable' nor 'Binary' are appropriate.+-- Introduced in version 1.2.2. toWords :: UUID -> (Word32, Word32, Word32, Word32) toWords (UUID w1 w2 w3 w4) = (w1, w2, w3, w4)  -- | Create a 'UUID' from a sequence of 'Word32'. The--- opposite of 'toWords'.+-- opposite of 'toWords'. Useful when you need a total+-- function for constructing 'UUID' values.+-- Introduced in version 1.2.2. fromWords :: Word32 -> Word32 -> Word32 -> Word32 -> UUID fromWords = UUID 
Data/UUID/V1.hs view
@@ -1,20 +1,27 @@ {-# OPTIONS_GHC -fno-cse #-} {-# LANGUAGE TypeFamilies #-} --- |--- Module      : Data.UUID.V1--- Copyright   : (c) 2008 Jason Dusek---               (c) 2009 Mark Lentczner---               (c) 2009-2010 Antoine Latter------ License     : BSD-style------ Maintainer  : aslatter@gmail.com--- Stability   : experimental--- Portability : portable------ RFC 4122 Version 1 UUID state machine.+{- |+Module      : Data.UUID.V1+Copyright   : (c) 2008 Jason Dusek+              (c) 2009 Mark Lentczner+              (c) 2009-2010,2012 Antoine Latter +License     : BSD-style++Maintainer  : aslatter@gmail.com+Stability   : experimental+Portability : portable++RFC 4122 Version 1 UUID state machine.++The generated UUID is based on the hardware MAC+address and the system clock.++If we cannot lookup the MAC address we seed the+generator with a psuedo-random number.+-}+ module Data.UUID.V1(nextUUID) where @@ -23,9 +30,12 @@ import Data.Bits import Data.Word +import Control.Applicative ((<$>),(<*>)) import Control.Concurrent.MVar import System.IO.Unsafe +import qualified System.Random as R+ import qualified System.Info.MAC as SysMAC import Data.MAC @@ -37,14 +47,12 @@ -- Is generated according to the Version 1 UUID sepcified in -- RFC 4122. ----- Returns nothing if the hardware MAC address could not--- be discovered.+-- Returns 'Nothing' if you request UUIDs too quickly. nextUUID :: IO (Maybe UUID) nextUUID = do   res <- stepTime-  mac <- SysMAC.mac-  case (res, mac) of-    (Just (c, t), Just m) -> return $ Just $ makeUUID t c m+  case res of+    Just (mac, c, t) -> return $ Just $ makeUUID t c mac     _ -> return Nothing  @@ -64,20 +72,20 @@ -- |Approximates the clock algorithm in RFC 4122, section 4.2 -- Isn't system wide or thread safe, nor does it properly randomize -- the clock value on initialization.-stepTime :: IO (Maybe (Word16, Word64))+stepTime :: IO (Maybe (MAC, Word16, Word64)) stepTime = do   h1 <- fmap hundredsOfNanosSinceGregorianReform getCurrentTime-  modifyMVar state $ \s@(State c0 h0) ->+  modifyMVar state $ \s@(State mac c0 h0) ->    if h1 > h0     then-      return (State c0 h1, Just (c0, h1))+      return (State mac c0 h1, Just (mac, c0, h1))     else       let         c1 = succ c0       in if c1 <= 0x3fff -- when clock is initially randomized,                       -- then this test will need to change          then-          return (State c1 h1, Just (c1, h1))+          return (State mac c1 h1, Just (mac, c1, h1))         else           return (s, Nothing) @@ -86,10 +94,33 @@ state :: MVar State state = unsafePerformIO $ do   h0 <- fmap hundredsOfNanosSinceGregorianReform getCurrentTime-  newMVar $ State 0 h0 -- the 0 should be a random number+  mac <- getMac+  newMVar $ State mac 0 h0 -- the 0 should be a random number +-- SysMAC.mac can fail on some machines.+-- In those cases we fake it with a random+-- 6 bytes seed.+getMac :: IO MAC+getMac =+    SysMAC.mac >>= \macM ->+    case macM of+      Just m -> return m+      Nothing -> randomMac +randomMac :: IO MAC+randomMac =+    -- I'm too lazy to thread through+    -- the random state ...+    MAC+     <$> R.randomIO+     <*> R.randomIO+     <*> R.randomIO+     <*> R.randomIO+     <*> R.randomIO+     <*> R.randomIO+ data State = State+    {-# UNPACK #-} !MAC     {-# UNPACK #-} !Word16     {-# UNPACK #-} !Word64  deriving (Show)
Data/UUID/V3.hs view
@@ -1,23 +1,28 @@--- |--- Module      : Data.UUID.V3--- Copyright   : (c) 2010 Antoine Latter------ License     : BSD-style------ Maintainer  : aslatter@gmail.com--- Stability   : experimental--- Portability : portable--------- This module implements Version 3 UUIDs as specified--- in RFC 4122.------ These UUIDs identify an object within a namespace,--- and are deterministic.------ The namespace is identified by a UUID.  Several sample--- namespaces are enclosed.+{- |+Module      : Data.UUID.V3+Copyright   : (c) 2010,2012 Antoine Latter +License     : BSD-style++Maintainer  : aslatter@gmail.com+Stability   : experimental+Portability : portable++NOTE: This module uses MD5 hashing. Unless you know+you need to use this module, you should probably be+using "Data.UUID.V5", which offers the same sort of+functionality as this module except implemented with+SHA-1 hashing.++This module implements Version 3 UUIDs as specified+in RFC 4122.++These UUIDs identify an object within a namespace,+and are deterministic.++The namespace is identified by a UUID.  Several sample+namespaces are enclosed.+-} module Data.UUID.V3     (generateNamed     ,Shared.namespaceDNS
+ Data/UUID/V4.hs view
@@ -0,0 +1,29 @@+{- |+   Module      : Data.UUID.V4+   Copyright   : (c) 2012 Antoine Latter++   License     : BSD-style++   Maintainer  : aslatter@gmail.com+   Stability   : experimental+   Portability : portable++   This module implements Version 4 UUIDs as specified+   in RFC 4122.++   These UUIDs are generated from a psuedo-random generator.+   We use the System.Random 'R.StdGen' as our random source.++   All of the logic is encapsulated in the 'R.Random' instance+   for the UUID type, so you are also free to use the random generator+   of your choice.+-}+module Data.UUID.V4 (nextRandom) where++import Data.UUID+import qualified System.Random as R++-- | Generate a random UUID. Introduced in version 1.2.6.+nextRandom :: IO UUID+nextRandom = R.randomIO+
uuid.cabal view
@@ -1,5 +1,5 @@ Name: uuid-Version: 1.2.5+Version: 1.2.6 Copyright: (c) 2008-2012 Antoine Latter Author: Antoine Latter Maintainer: aslatter@gmail.com@@ -33,6 +33,7 @@    Data.UUID    Data.UUID.V1    Data.UUID.V3+   Data.UUID.V4    Data.UUID.V5   Other-Modules:@@ -41,8 +42,6 @@    Data.UUID.Named   Extensions: DeriveDataTypeable- Ghc-Prof-Options:   -auto-all -caf-all- Ghc-Shared-Options:  Ghc-Options:        -Wall  source-repository   head