2011-11-11 22:53:17 +00:00
|
|
|
module Tests.PubKey
|
2012-03-28 07:06:13 +00:00
|
|
|
( arbitraryRSAPair
|
|
|
|
, globalRSAPair
|
|
|
|
, getGlobalRSAPair
|
|
|
|
) where
|
2011-11-11 22:53:17 +00:00
|
|
|
|
|
|
|
import Test.QuickCheck
|
|
|
|
|
|
|
|
import qualified Crypto.Random.AESCtr as RNG
|
2012-12-05 07:47:17 +00:00
|
|
|
import qualified Crypto.PubKey.RSA as RSA
|
2011-11-11 22:53:17 +00:00
|
|
|
|
|
|
|
import qualified Data.ByteString as B
|
|
|
|
|
2011-11-14 22:09:15 +00:00
|
|
|
import Control.Concurrent.MVar
|
|
|
|
import System.IO.Unsafe
|
|
|
|
|
2011-11-11 22:53:17 +00:00
|
|
|
arbitraryRSAPair :: Gen (RSA.PublicKey, RSA.PrivateKey)
|
|
|
|
arbitraryRSAPair = do
|
2012-12-04 08:35:21 +00:00
|
|
|
rng <- (maybe (error "making rng") id . RNG.make . B.pack) `fmap` vector 64
|
2012-03-28 07:06:13 +00:00
|
|
|
arbitraryRSAPairWithRNG rng
|
2011-11-14 22:09:15 +00:00
|
|
|
|
2012-12-05 07:47:17 +00:00
|
|
|
arbitraryRSAPairWithRNG rng = return $ fst $ RSA.generate rng 128 0x10001
|
2011-11-14 22:09:15 +00:00
|
|
|
|
|
|
|
{-# 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)
|