on master help sign in
Use `cryptonite` to implement `V4.nextRandom`.
bd60ffeAntoine Latter
uuid/Data/UUID/V4.hs+9−3
@@ -1,6 +1,6 @@
1{- |
1{- |
2 Module : Data.UUID.V4
2 Module : Data.UUID.V4
3− Copyright : (c) 2012 Antoine Latter
3+ Copyright : (c) 2012-2016 Antoine Latter
4
4
5 License : BSD-style
5 License : BSD-style
6
6
@@ -21,8 +21,14 @@
21module Data.UUID.V4 (nextRandom) where
21module Data.UUID.V4 (nextRandom) where
22
22
23import Data.UUID
23import Data.UUID
24−import qualified System.Random as R
24+import Data.UUID.Types.Internal ( buildFromBytes )
25+
26+import Crypto.Random.Entropy ( getEntropy )
27+import Data.ByteString ( unpack )
25
28
26-- | Generate a random UUID. Introduced in version 1.2.6.
29-- | Generate a random UUID. Introduced in version 1.2.6.
27nextRandom :: IO UUID
30nextRandom :: IO UUID
28−nextRandom = R.randomIO
31+nextRandom = do
32+ [b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bb, bc, bd, be, bf]
33+ <- unpack `fmap` getEntropy 16
34+ return $ buildFromBytes 4 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf