hs-tls/core/Tests/PubKey.hs

31 lines
917 B
Haskell
Raw Normal View History

module Tests.PubKey
2012-03-28 07:06:13 +00:00
( arbitraryRSAPair
, globalRSAPair
, getGlobalRSAPair
) where
import Test.QuickCheck
import qualified Crypto.Random.AESCtr as RNG
import qualified Crypto.PubKey.RSA as RSA
import qualified Data.ByteString as B
import Control.Concurrent.MVar
import System.IO.Unsafe
arbitraryRSAPair :: Gen (RSA.PublicKey, RSA.PrivateKey)
arbitraryRSAPair = do
rng <- (maybe (error "making rng") id . RNG.make . B.pack) `fmap` vector 64
2012-03-28 07:06:13 +00:00
arbitraryRSAPairWithRNG rng
arbitraryRSAPairWithRNG rng = return $ fst $ RSA.generate rng 128 0x10001
{-# NOINLINE globalRSAPair #-}
globalRSAPair :: MVar (RSA.PublicKey, RSA.PrivateKey)
globalRSAPair = unsafePerformIO (RNG.makeSystem >>= arbitraryRSAPairWithRNG >>= newMVar)
{-# NOINLINE getGlobalRSAPair #-}
getGlobalRSAPair :: (RSA.PublicKey, RSA.PrivateKey)
getGlobalRSAPair = unsafePerformIO (readMVar globalRSAPair)