test_rand.py 794 B

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (c) Frederick Dean
  2. # See LICENSE for details.
  3. """
  4. Unit tests for `OpenSSL.rand`.
  5. """
  6. import pytest
  7. from OpenSSL import rand
  8. class TestRand(object):
  9. @pytest.mark.parametrize("args", [(b"foo", None), (None, 3)])
  10. def test_add_wrong_args(self, args):
  11. """
  12. `OpenSSL.rand.add` raises `TypeError` if called with arguments not of
  13. type `str` and `int`.
  14. """
  15. with pytest.raises(TypeError):
  16. rand.add(*args)
  17. def test_add(self):
  18. """
  19. `OpenSSL.rand.add` adds entropy to the PRNG.
  20. """
  21. rand.add(b"hamburger", 3)
  22. def test_status(self):
  23. """
  24. `OpenSSL.rand.status` returns `1` if the PRNG has sufficient entropy,
  25. `0` otherwise.
  26. """
  27. assert rand.status() == 1