diff options
author | Robey Pointer <robey@lag.net> | 2008-03-23 23:51:39 -0700 |
---|---|---|
committer | Robey Pointer <robey@lag.net> | 2008-03-23 23:51:39 -0700 |
commit | f5f203d5eaffa7496bcf8684050d9e83970a1bb1 (patch) | |
tree | f383eac2deffaef8bb96f1c552c2ac681de64422 | |
parent | f35a65bb0c26b15ee4e84bc5714dda16eb156a9d (diff) |
[project @ robey@lag.net-20080324065139-nmvo5goh1izbd3gr]
not all windows boxes have winrandom
-rw-r--r-- | paramiko/osrandom.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/paramiko/osrandom.py b/paramiko/osrandom.py index 447d090e..6c559e02 100644 --- a/paramiko/osrandom.py +++ b/paramiko/osrandom.py @@ -37,6 +37,13 @@ try: except ImportError: winrandom = None +# Lastly, try to get the plain "RandomPool" +# (sometimes windows doesn't even have winrandom!) +try: + from Crypto.Util.randpool import RandomPool +except ImportError: + RandomPool = None + ## ## Define RandomPool classes @@ -88,6 +95,15 @@ class DevUrandomPool(BaseOSRandomPool): return bytes +class FallbackRandomPool (BaseOSRandomPool): + def __init__(self): + self._wr = RandomPool() + self.randomize() + + def get_bytes(self, n): + return self._wr.get_bytes(n) + + ## ## Detect default random number source ## @@ -103,6 +119,11 @@ if osrandom_source is None and winrandom is not None: osrandom_source = "winrandom" DefaultRandomPoolClass = WinRandomPool +# Try final fallback +if osrandom_source is None and RandomPool is not None: + osrandom_source = "randompool" + DefaultRandomPoolClass = FallbackRandomPool + # Give up if osrandom_source is None: raise ImportError("Cannot find OS entropy source") |