diff options
-rw-r--r-- | paramiko/hostkeys.py | 26 |
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 |