def hasHostKey(self, hostname, key): """ Check for an entry with matching hostname and key. @param hostname: A hostname or IP address literal to check for. @type hostname: L{bytes} @param key: The public key to check for. @type key: L{Key} @return: C{True} if the given hostname and key are present in this file, C{False} if they are not. @rtype: L{bool} @raise HostKeyChanged: if the host key found for the given hostname does not match the given key. """ for lineidx, entry in enumerate(self.iterentries(), -len(self._added)): if entry.matchesHost(hostname) and entry.keyType == key.sshType(): if entry.matchesKey(key): return True else: # Notice that lineidx is 0-based but HostKeyChanged.lineno # is 1-based. if lineidx < 0: line = None path = None else: line = lineidx + 1 path = self._savePath raise HostKeyChanged(entry, path, line) return False
def hasHostKey(self, hostname, key): """ @return: True if the given hostname and key are present in this file, False if they are not. @rtype: L{bool} @raise HostKeyChanged: if the host key found for the given hostname does not match the given key. """ for lineidx, entry in enumerate(self._entries): if entry.matchesHost(hostname): if entry.matchesKey(key): return True else: raise HostKeyChanged(entry, self._savePath, lineidx + 1) return False