on master help sign in
rollback dropping maccathcer and version bump
commitc0886594fe86fec5a6b2af04597d9b520086158b authorAntoine Latter <aslatter@gmail.com> dateWed 24 Feb 2010, 03:38 (17 years ago) parent81abbd4
4 files changed+17−23
Data/UUID/V1.hs+11−13 tests/BenchUUID.hs+1−5 tests/TestUUID.hs+1−1 uuid.cabal+4−4
Data/UUID/V1.hs+11−13
@@ -12,12 +12,8 @@
1212-- Portability : portable
1313--
1414-- RFC 4122 Version 1 UUID state machine.
15−--
16−-- Currently this is more useful as a reference. For
17−-- true machine-unique UUID generation see the
18−-- system-uuid package.
1915
20−module Data.UUID.V1(nextUUID, MAC(..))
16+module Data.UUID.V1(nextUUID)
2117where
2218
2319import Data.Time
@@ -29,6 +25,9 @@ import Data.IORef
2925import System.IO
3026import System.IO.Unsafe
3127
28+import qualified System.Info.MAC as SysMAC
29+import Data.MAC
30+
3231import Data.UUID.Builder
3332import Data.UUID.Internal
3433
@@ -37,12 +36,14 @@ import Data.UUID.Internal
3736-- Is generated according to the Version 1 UUID sepcified in
3837-- RFC 4122.
3938--
40−-- Returns nothing if UUIDs are generated to quickly
41−nextUUID :: MAC -> IO (Maybe UUID)
42−nextUUID m = do
39+-- Returns nothing if the hardware MAC address could not
40+-- be discovered.
41+nextUUID :: IO (Maybe UUID)
42+nextUUID = do
4343 res <- stepTime
44− case res of
45− Just (c, t) -> return $ Just $ makeUUID t c m
44+ mac <- SysMAC.mac
45+ case (res, mac) of
46+ (Just (c, t), Just m) -> return $ Just $ makeUUID t c m
4647 _ -> return Nothing
4748
4849
@@ -58,9 +59,6 @@ instance ByteSource MACSource where
5859 z /-/ (MACSource (MAC a b c d e f)) = z a b c d e f
5960type instance ByteSink MACSource g = Takes3Bytes (Takes3Bytes g)
6061
61−-- | Machine address of computer generating UUIDs.
62−data MAC = MAC !Word8 !Word8 !Word8
63− !Word8 !Word8 !Word8
6462
6563-- |Approximates the clock algorithm in RFC 4122, section 4.2
6664-- Isn't system wide or thread safe, nor does it properly randomize
tests/BenchUUID.hs+1−5
@@ -58,7 +58,7 @@ main = do
5858 bench "fromByteString" $ nf U.fromByteString b1
5959 ],
6060 bgroup "generation" [
61− bench "V1" $ nfIO (U.nextUUID testMAC),
61+ bench "V1" $ nfIO U.nextUUID,
6262 bench "V4" $ nfIO (randomUUID :: IO U.UUID),
6363 bench "V3" $ nf (U3.generateNamed U3.namespaceURL) n1,
6464 bench "V5" $ nf (U5.generateNamed U5.namespaceURL) n1
@@ -66,10 +66,6 @@ main = do
6666 bench "set making" $ nf Set.fromList uuids
6767 ]
6868
69−-- | MAC address to use in testing
70−testMAC :: U.MAC
71−testMAC = U.MAC 0 0 0 0 0 0
72−
7369-- 50 uuids, so tests can be repeatable
7470uuids :: [U.UUID]
7571uuids
tests/TestUUID.hs+1−1
@@ -138,7 +138,7 @@ prop_v5Valid = label "V5 valid" v5Valid
138138
139139main :: IO ()
140140main = do
141− v1s <- replicateM 100 $ U.nextUUID $ U.MAC 0 0 0 0 0 0
141+ v1s <- replicateM 100 U.nextUUID
142142 runTestText (putTextToHandle stderr False) (TestList [
143143 test_null,
144144 test_nil,
uuid.cabal+4−4
@@ -1,5 +1,5 @@
11Name: uuid
2−Version: 1.3.0
2+Version: 1.2.0
33Copyright: (c) 2008-2009 Antoine Latter
44Author: Antoine Latter
55Maintainer: aslatter@gmail.com
@@ -29,7 +29,7 @@ Flag test
2929 Default: False
3030
3131Library
32− Build-Depends: random, binary, bytestring, Crypto,
32+ Build-Depends: random, binary, bytestring, Crypto, maccatcher,
3333 time, base >=3, base < 5
3434
3535 Exposed-Modules:
@@ -54,7 +54,7 @@ Executable benchuuid
5454 Extensions: DeriveDataTypeable, CPP
5555 If flag(test)
5656 Buildable: True
57− Build-Depends: random, binary, bytestring, Crypto,
57+ Build-Depends: random, binary, bytestring, Crypto, maccatcher,
5858 time, base >=3, base < 5, containers,
5959 criterion >= 0.3 && < 0.5, parallel >= 2.1 && < 2.3,
6060 mersenne-random-pure64 >= 0.2 && < 0.3
@@ -71,7 +71,7 @@ Executable testuuid
7171
7272 If flag(test)
7373 Buildable: True
74− Build-Depends: random, binary, bytestring, Crypto,
74+ Build-Depends: random, binary, bytestring, Crypto, maccatcher,
7575 time, base >=3, base < 5,
7676 HUnit >=1.2 && < 1.3, QuickCheck >=1.2 && < 1.3
7777 Else