Merge pull request #12 from ibotty/master
copy withRandomBytes from crypto-random
This commit is contained in:
commit
268f059470
@ -13,6 +13,7 @@ module Crypto.Random
|
|||||||
, drgNew
|
, drgNew
|
||||||
, drgNewTest
|
, drgNewTest
|
||||||
, withDRG
|
, withDRG
|
||||||
|
, withRandomBytes
|
||||||
, DRG(..)
|
, DRG(..)
|
||||||
-- * Random abstraction
|
-- * Random abstraction
|
||||||
, MonadRandom(..)
|
, MonadRandom(..)
|
||||||
@ -22,7 +23,7 @@ module Crypto.Random
|
|||||||
import Crypto.Random.Types
|
import Crypto.Random.Types
|
||||||
import Crypto.Random.ChaChaDRG
|
import Crypto.Random.ChaChaDRG
|
||||||
import Crypto.Random.Entropy
|
import Crypto.Random.Entropy
|
||||||
import Data.ByteArray (ScrubbedBytes)
|
import Data.ByteArray (ByteArray, ScrubbedBytes)
|
||||||
import Crypto.Internal.Imports
|
import Crypto.Internal.Imports
|
||||||
|
|
||||||
-- | Create a new DRG from system entropy
|
-- | Create a new DRG from system entropy
|
||||||
@ -38,3 +39,10 @@ drgNew = initialize <$> (getEntropy 40 :: IO ScrubbedBytes)
|
|||||||
-- has been properly randomly generated.
|
-- has been properly randomly generated.
|
||||||
drgNewTest :: (Word64, Word64, Word64, Word64, Word64) -> ChaChaDRG
|
drgNewTest :: (Word64, Word64, Word64, Word64, Word64) -> ChaChaDRG
|
||||||
drgNewTest = initializeWords
|
drgNewTest = initializeWords
|
||||||
|
|
||||||
|
-- | Generate @len random bytes and mapped the bytes to the function @f.
|
||||||
|
--
|
||||||
|
-- This is equivalent to use Control.Arrow 'first' with 'randomBytesGenerate'
|
||||||
|
withRandomBytes :: (ByteArray ba, DRG g) => g -> Int -> (ba -> a) -> (a, g)
|
||||||
|
withRandomBytes rng len f = (f bs, rng')
|
||||||
|
where (bs, rng') = randomBytesGenerate len rng
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user