Ñò )p±Uc@s†dZddklZddkZddkZddklZlZddkl Z defd„ƒYZ e djo eƒndS( s! Unit tests for L{OpenSSL.rand}. iÿÿÿÿ(tmainN(tTestCasetb(trandt RandTestscBseZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„ZRS(cCsF|ittiƒ|ittidƒ|ittiddƒdS(s L{OpenSSL.rand.bytes} raises L{TypeError} if called with the wrong number of arguments or with a non-C{int} argument. iN(t assertRaisest TypeErrorRtbytestNone(tself((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyttest_bytes_wrong_argsscCs¡tidƒ}|it|ƒdƒtiddƒ}|i||ƒtiddƒ}|it|ƒdƒ|ittidƒ}|it|ƒdƒdS(s® Verify that we can obtain bytes from rand_bytes() and that they are different each time. Test the parameter of rand_bytes() for bad values. i2t num_bytesiiÿÿÿÿsnum_bytes must not be negativeN(RRt assertEqualtlentassertNotEqualRt ValueErrortstr(R tb1tb2tb3texc((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyt test_bytesscCsq|ittiƒ|ittitdƒdƒ|ittiddƒ|ittitdƒddƒdS(s£ When called with the wrong number of arguments, or with arguments not of type C{str} and C{int}, L{OpenSSL.rand.add} raises L{TypeError}. tfooiN(RRRtaddRR(R ((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyttest_add_wrong_args,scCstitdƒdƒdS(s? L{OpenSSL.rand.add} adds entropy to the PRNG. t hamburgeriN(RRR(R ((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyttest_add7scCsL|ittiƒ|ittidƒ|ittitdƒdƒdS(s’ When called with the wrong number of arguments, or with a non-C{str} argument, L{OpenSSL.rand.seed} raises L{TypeError}. RN(RRRtseedRR(R ((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyttest_seed_wrong_args>scCstitdƒƒdS(s@ L{OpenSSL.rand.seed} adds entropy to the PRNG. s milk shakeN(RRR(R ((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyt test_seedHscCs|ittidƒdS(sd L{OpenSSL.rand.status} raises L{TypeError} when called with any arguments. N(RRRtstatusR(R ((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyttest_status_wrong_argsOscCs|itiƒdjƒdS(sx L{OpenSSL.rand.status} returns C{True} if the PRNG has sufficient entropy, C{False} otherwise. iiN(ii(t assertTrueRR(R ((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyt test_statusWscCs{|ittiƒ|ittidƒ|ittiddƒ|ittiddƒ|ittidddƒdS(s¡ L{OpenSSL.rand.egd} raises L{TypeError} when called with the wrong number of arguments or with arguments not of type C{str} and C{int}. RiN(RRRtegdR(R ((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyttest_egd_wrong_argsbs cCs?ti|iƒƒ}d}|i||jd||fƒdS(sr L{OpenSSL.rand.egd} returns C{0} or C{-1} if the EGD socket passed to it does not exist. iÿÿÿÿis %r not in %rN(iÿÿÿÿi(RR"tmktempR (R tresulttexpected((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyttest_egd_missingns  cCs|ittidƒdS(se L{OpenSSL.rand.cleanup} raises L{TypeError} when called with any arguments. N(RRRtcleanupR(R ((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyttest_cleanup_wrong_argszscCs|itiƒdƒdS(sk L{OpenSSL.rand.cleanup} releases the memory used by the PRNG and returns C{None}. N(tassertIdenticalRR(R(R ((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyt test_cleanup‚scCse|ittiƒ|ittiddƒ|ittiddƒ|ittidddƒdS(s L{OpenSSL.rand.load_file} raises L{TypeError} when called the wrong number of arguments or arguments not of type C{str} and C{int}. RiN(RRRt load_fileR(R ((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyttest_load_file_wrong_argsŠscCsF|ittiƒ|ittidƒ|ittiddƒdS(s‘ L{OpenSSL.rand.write_file} raises L{TypeError} when called with the wrong number of arguments or a non-C{str} argument. RN(RRRt write_fileR(R ((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyttest_write_file_wrong_args•scCsŽ|iƒ}t|dƒ}|iƒzTti|ƒti|ƒti}|i|dƒti |ƒti |dƒWdti |ƒXdS(sG Test reading and writing of files via rand functions. twiiN( R$topentcloseRR.toststattST_SIZEt assertEqualsR,tunlink(R ttmpfiletfObjtsize((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyt test_filesŸs    (t__name__t __module__R RRRRRRR!R#R'R)R+R-R/R;(((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyRs       t__main__( t__doc__tunittestRR3R4tOpenSSL.test.utilRRtOpenSSLRRR<(((s</usr/lib64/python2.6/site-packages/OpenSSL/test/test_rand.pyts  ¥