meteficha/crypto-conduit — Issue #1: Source RNG?
Author: TomMD
Created: 2012-01-11 18:11:34+00:00
State: open

Is there a reason not to have a source for random numbers? Something like:

sourceRNG :: (ResourceIO m, CryptoRandomGen g) => Seed -> Bytes-> Proxy g -> Source m ByteString

Allowing code to be something like the below if you like tagging. If you don't like tagging I'm not sure how to make a phantom type get carried implicitly inside Source - perhaps by making the result a tuple of (g,ByteString)? that would be ugly though.

rngSource :: (ResourceIO m, CryptoRandomGen g) => Tagged g (Source m ByteString)
rngSource = do
let p = Proxy
entLen = genSeedLength `proxy` p
ent <- getEntropy entLen
sourceRNG ent 128 p