fallback.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #
  2. # Random/OSRNG/fallback.py : Fallback entropy source for systems with os.urandom
  3. #
  4. # Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net>
  5. #
  6. # ===================================================================
  7. # The contents of this file are dedicated to the public domain. To
  8. # the extent that dedication to the public domain is not available,
  9. # everyone is granted a worldwide, perpetual, royalty-free,
  10. # non-exclusive license to exercise all rights associated with the
  11. # contents of this file for any purpose whatsoever.
  12. # No rights are reserved.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  18. # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  19. # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. # SOFTWARE.
  22. # ===================================================================
  23. __revision__ = "$Id$"
  24. __all__ = ['PythonOSURandomRNG']
  25. import os
  26. from rng_base import BaseRNG
  27. class PythonOSURandomRNG(BaseRNG):
  28. name = "<os.urandom>"
  29. def __init__(self):
  30. self._read = os.urandom
  31. BaseRNG.__init__(self)
  32. def _close(self):
  33. self._read = None
  34. def new(*args, **kwargs):
  35. return PythonOSURandomRNG(*args, **kwargs)
  36. # vim:set ts=4 sw=4 sts=4 expandtab: