File: //usr/local/CyberPanel/lib64/python3.10/site-packages/paramiko/__pycache__/hostkeys.cpython-310.pyc
o
�h�3 � @ 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
e�ZG dd� de�ZG d
d� d�ZdS )� )�encodebytes�decodebytesN)�MutableMapping)�sha1)�HMAC)�PKey�UnknownKeyType)�
get_logger�constant_time_bytes_eq�b�u)�SSHExceptionc @ s� e Zd ZdZd#dd�Zdd� 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 | _ |dur| �|� dS 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)�_entries�load)�self�filename� r �G/usr/local/CyberPanel/lib/python3.10/site-packages/paramiko/hostkeys.py�__init__/ s �zHostKeys.__init__c C sH | j D ]}||jv r|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 � hostnames�key�get_name�append�HostKeyEntry)r �hostname�keytyper �er r r �add; s
�zHostKeys.addc
C s� t |d��Z}t|d�D ]K\}}|�� }t|�dks|d dkr qzt�||�}W n ty1 Y qw |durV|j}|D ]}| �||j �rJ|j�
|� q;t|j�rV| j�|� qW d � dS 1 sbw Y 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� enumerate�strip�lenr � from_liner
r �checkr �remover r )r r �f�lineno�line�entry�
_hostnames�hr r r r J s* ��
��"�z
HostKeys.loadc C sR t |d��}| jD ]
}|�� }|r|�|� q W d � dS 1 s"w Y dS )a�
Save host keys into a file, in the format used by OpenSSH. The order
of keys in the file will be preserved when possible (if these keys were
loaded from a file originally). The single exception is that combined
lines will be split into individual key lines, which is arguably a bug.
:param str filename: name of the file to write
:raises: ``IOError`` -- if there was an error writing the file
.. versionadded:: 1.6.1
�wN)r"