U vf3 @ s d dl mZmZ d dlZd dlZd dlZd dlmZ d dlm Z d dl mZ d dlm Z mZ d dlmZmZmZmZ d dlmZ G d d d eZG dd deZG d d dZdS ) )encodebytesdecodebytesN)MutableMapping)sha1)HMAC)PKeyUnknownKeyType) get_loggerconstant_time_bytes_eqbu)SSHExceptionc @ s e Zd ZdZd#ddZdd Zdd Zd d Zdd Zd d Z dd Z dd Zdd Zdd Z dd Zdd Zdd Zdd Zdd Zed$d!d"ZdS )%HostKeysaZ Representation of an OpenSSH-style "known hosts" file. Host keys can be read from one or more files, and then individual hosts can be looked up to verify server keys during SSH negotiation. A `.HostKeys` object can be treated like a dict; any dict lookup is equivalent to calling `lookup`. .. versionadded:: 1.5.3 Nc C s g | _ |dk r| | dS )z Create a new HostKeys object, optionally loading keys from an OpenSSH style host-key file. :param str filename: filename to load host keys from, or ``None`` N)_entriesload)selffilename r B/opt/alt/python38/lib/python3.8/site-packages/paramiko/hostkeys.py__init__/ s zHostKeys.__init__c C sH | j D ](}||jkr|j |kr||_ dS q| j t|g| dS )a. Add a host key entry to the table. Any existing entry for a ``(hostname, keytype)`` pair will be replaced. :param str hostname: the hostname (or IP) to add :param str keytype: key type (``"ssh-rsa"`` or ``"ssh-dss"``) :param .PKey key: the key to add N)r hostnameskeyget_nameappendHostKeyEntry)r hostnameZkeytyper er r r add; s zHostKeys.addc C s t |d}t|dD ]\}}| }t|dks|d dkr@qzt||}W n tk rh Y qY nX |dk r|j}|D ]}| ||j r||j | q|t|jr| j| qW 5 Q R X dS )a] Read a file of known SSH host keys, in the format used by OpenSSH. This type of file unfortunately doesn't exist on Windows, but on posix, it will usually be stored in ``os.path.expanduser("~/.ssh/known_hosts")``. If this method is called multiple times, the host keys are merged, not cleared. So multiple calls to `load` will just call `add`, replacing any existing entries and adding new ones. :param str filename: name of the file to read host keys from :raises: ``IOError`` -- if there was an error reading the file r r #N) open enumeratestriplenr from_liner r checkr remover r )r r flinenolineentryZ _hostnameshr r r r J s z HostKeys.loadc C s<