File: //lib/python3/dist-packages/twisted/conch/client/__pycache__/knownhosts.cpython-38.pyc
U
s�@g�M � @ sf d Z ddlmZmZ ddlZddlmZmZm Z ddl
mZ ddlm
Z
ddlZddlmZ ddlmZ dd lmZmZmZ dd
lmZmZmZ ddlmZ ddlmZ dd
lm Z m!Z! ddl"m#Z# ddl$m%Z% dd� Z&dd� Z'G dd� de(�Z)ee�G dd� de)��Z*ee�G dd� de(��Z+dd� Z,ee�G dd� de)e%��Z-G dd� de(�Z.G d d!� d!e(�Z/dS )"zE
An implementation of the OpenSSH known_hosts database.
@since: 8.2
� )�absolute_import�divisionN)�Error�
b2a_base64�
a2b_base64)�closing)�sha1)�implementer)�IKnownHostEntry)�HostKeyChanged�UserRejectedKey�InvalidEntry)�Key�BadKeyError�FingerprintFormats)�defer)�log)�nativeString�unicode)�secureRandom)�FancyEqMixinc C s t | ��� S )z�
Encode a binary string as base64 with no trailing newline.
@param s: The string to encode.
@type s: L{bytes}
@return: The base64-encoded string.
@rtype: L{bytes}
)r �strip)�s� r �A/usr/lib/python3/dist-packages/twisted/conch/client/knownhosts.py�
_b64encode s
r c C sz | � dd�}t|�dkrt� �|\}}}|� dd�}t|�dkrT|\}}|�d�}n|d }d}t�t|��}||||fS )a�
Extract common elements of base64 keys from an entry in a hosts file.
@param string: A known hosts file entry (a single line).
@type string: L{bytes}
@return: a 4-tuple of hostname data (L{bytes}), ssh key type (L{bytes}), key
(L{Key}), and comment (L{bytes} or L{None}). The hostname data is
simply the beginning of the line up to the first occurrence of
whitespace.
@rtype: L{tuple}
N� � � �
r )�split�lenr
�rstripr �
fromStringr ) �string�elements� hostnames�keyTypeZ
keyAndCommentZsplitkeyZ keyString�comment�keyr r r �_extractCommon- s
r* c @ s e Zd ZdZdd� Zdd� ZdS )�
_BaseEntrya�
Abstract base of both hashed and non-hashed entry objects, since they
represent keys and key types the same way.
@ivar keyType: The type of the key; either ssh-dss or ssh-rsa.
@type keyType: L{bytes}
@ivar publicKey: The server public key indicated by this line.
@type publicKey: L{twisted.conch.ssh.keys.Key}
@ivar comment: Trailing garbage after the key line.
@type comment: L{bytes}
c C s || _ || _|| _d S �N)r'