hs-tls/Tests/Certificate.hs

49 lines
1.3 KiB
Haskell
Raw Normal View History

2010-12-06 08:07:05 +00:00
module Tests.Certificate
( arbitraryX509
) where
import Test.QuickCheck
import qualified Data.Certificate.X509 as X509
2011-02-20 08:35:14 +00:00
import qualified Data.Certificate.X509Cert as X509Cert
2010-12-06 08:07:05 +00:00
import Control.Monad
readableChar :: Gen Char
readableChar = elements (['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'])
arbitraryDN = return []
2010-12-06 08:07:05 +00:00
arbitraryTime = do
year <- choose (1951, 2050)
month <- choose (1, 12)
day <- choose (1, 30)
hour <- choose (0, 23)
minute <- choose (0, 59)
second <- choose (0, 59)
z <- arbitrary
return (year, month, day, hour, minute, second, z)
2011-02-20 17:42:05 +00:00
arbitraryX509Cert pubKey = do
version <- choose (1,3)
serial <- choose (0,2^24)
2010-12-06 08:07:05 +00:00
issuerdn <- arbitraryDN
subjectdn <- arbitraryDN
time1 <- arbitraryTime
time2 <- arbitraryTime
let sigalg = X509.SignatureALG_md5WithRSAEncryption
2011-02-20 08:35:14 +00:00
return $ X509Cert.Certificate
2010-12-06 08:07:05 +00:00
{ X509.certVersion = version
, X509.certSerial = serial
, X509.certSignatureAlg = sigalg
2010-12-06 08:07:05 +00:00
, X509.certIssuerDN = issuerdn
, X509.certSubjectDN = subjectdn
, X509.certValidity = (time1, time2)
, X509.certPubKey = pubKey
, X509.certExtensions = Nothing
}
2011-02-20 08:35:14 +00:00
arbitraryX509 pubKey = do
cert <- arbitraryX509Cert pubKey
sig <- resize 40 $ listOf1 arbitrary
let sigalg = X509.SignatureALG_md5WithRSAEncryption
2011-05-09 08:06:45 +00:00
return (X509.X509 cert Nothing Nothing sigalg sig)