summaryrefslogtreecommitdiff
path: root/paramiko/hostkeys.py
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2017-06-01 13:07:50 -0700
committerJeff Forcier <jeff@bitprophet.org>2017-06-01 13:07:50 -0700
commitaa7963276816cc539315f62e4657bcc579085739 (patch)
tree4f98c202043e760043a2fe3c045516e020a82f8f /paramiko/hostkeys.py
parent6a25d1ca38f2a1a8eecb20185f368c98680f7035 (diff)
downloadparamiko-aa7963276816cc539315f62e4657bcc579085739.tar.gz
Refactor HostKeys' scan-for-entry code
Diffstat (limited to 'paramiko/hostkeys.py')
-rw-r--r--paramiko/hostkeys.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/paramiko/hostkeys.py b/paramiko/hostkeys.py
index f5c622ed..4be3fd42 100644
--- a/paramiko/hostkeys.py
+++ b/paramiko/hostkeys.py
@@ -186,18 +186,28 @@ class HostKeys (MutableMapping):
entries = []
for e in self._entries:
- for h in e.hostnames:
- if (
- h == hostname or
- h.startswith('|1|') and
- not hostname.startswith('|1|') and
- constant_time_bytes_eq(self.hash_host(hostname, h), h)
- ):
- entries.append(e)
+ if self._hostname_matches(hostname, e):
+ entries.append(e)
if len(entries) == 0:
return None
return SubDict(hostname, entries, self)
+ def _hostname_matches(self, hostname, entry):
+ """
+ Tests whether ``hostname`` string matches given SubDict ``entry``.
+
+ :returns bool:
+ """
+ for h in entry.hostnames:
+ if (
+ h == hostname or
+ h.startswith('|1|') and
+ not hostname.startswith('|1|') and
+ constant_time_bytes_eq(self.hash_host(hostname, h), h)
+ ):
+ return True
+ return False
+
def check(self, hostname, key):
"""
Return True if the given key is associated with the given hostname