%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/conch/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/conch/test/__pycache__/test_ckeygen.cpython-312.pyc

�

Ϫ�f-m���dZddlmZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddl	mZddlm
Z
mZmZmZmZddlmZdd	lmZdd
lmZed�rddlmZmZmZmZmZmZdd
lm Z m!Z!m"Z"m#Z#ndZ$dd�Z%Gd�de�Z&y)z-
Tests for L{twisted.conch.scripts.ckeygen}.
�)�annotationsN)�StringIO)�Callable)�NoReturn)�privateECDSA_openssh�privateEd25519_openssh_new�privateRSA_openssh�privateRSA_openssh_encrypted�publicRSA_openssh)�FilePath)�
requireModule)�TestCase�cryptography)�_getKeyOrDefault�_saveKey�changePassPhrase�displayPublicKey�enumrepresentation�printFingerprint)�BadFingerPrintFormat�BadKeyError�FingerprintFormats�Keyz7cryptography required for twisted.conch.scripts.ckeygenc�*��t|��d�fd�}|S)a@
    Return a callable to patch C{getpass.getpass}.  Yields a passphrase each
    time called. Use case is to provide an old, then new passphrase(s) as if
    requested interactively.

    @param passphrases: The list of passphrases returned, one per each call.

    @return: A callable to patch C{getpass.getpass}.
    c���t��S�N)�next)�_�passphrasesIters ��A/usr/lib/python3/dist-packages/twisted/conch/test/test_ckeygen.py�fakeGetpassz makeGetpass.<locals>.fakeGetpass=s����O�$�$�)r�object�return�str)�iter)�passphrasesr!rs  @r �makeGetpassr(1s����;�'�O�%��r"c�d�eZdZdZd+d�Z		d,							d-d�Zd+d�Zd+d�Zd+d�Zd+d�Z	d+d	�Z
d+d
�Zd+d�Zd+d�Z
d+d
�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Zd+d�Z d+d �Z!d+d!�Z"d+d"�Z#d+d#�Z$d+d$�Z%d+d%�Z&d+d&�Z'd+d'�Z(d+d(�Z)d+d)�Z*d+d*�Z+y).�KeyGenTestszN
    Tests for various functions used to implement the I{ckeygen} script.
    c�d�t�|_|jtd|j�y)zX
        Patch C{sys.stdout} so tests can make assertions about what's printed.
        �stdoutN)rr,�patch�sys��selfs r �setUpzKeyGenTests.setUpHs!���j����
�
�3��$�+�+�.r"Nc��|j�}dd|d|dg}|�|jd|g�|�|jd|g�	tj|�tj|�}tj|d	z�}|d
k(r!|j|j�d�nT|dk(r!|j|j�d
�n.|j|j�|j��|j|j��y#t$rd|d<tj|�Y��wxYw)N�ckeygen�-t�-fz--no-passphrasez-bz--private-key-subtype�ckeygen3r�.pub�ecdsa�EC�ed25519�Ed25519)�mktemp�extend�
subprocess�call�FileNotFoundErrorr�fromFile�assertEqual�type�upper�
assertTrue�isPublic)r0�keyType�keySize�privateKeySubtype�filename�args�privKey�pubKeys        r �_testrunzKeyGenTests._testrunOs���;�;�=���4��$��:K�L�����K�K��w��(��(��K�K�0�2C�D�E�	"��O�O�D�!��,�,�x�(�����h��/�0���g�����W�\�\�^�T�2�
�	�
!����W�\�\�^�Y�7����W�\�\�^�W�]�]�_�=�������)�*��!�	"� �D��G��O�O�D�!�	"�s�D � #E�Ec���|jdd�|jddd��|jd�|jdd��|jd�|jdd�|jddd��|jd�|jdd��|jdd�|jddd��|jd�|jdd��y)	Nr8�384�v1)rIr:�dsa�2048�rsa)rNr/s r �test_keygenerationzKeyGenTests.test_keygenerationjs����
�
�g�u�%��
�
�g�u��
�=��
�
�g���
�
�g��
�6��
�
�i� ��
�
�e�V�$��
�
�e�V�t�
�<��
�
�e���
�
�e�t�
�4��
�
�e�V�$��
�
�e�V�t�
�<��
�
�e���
�
�e�t�
�4r"c
�z�|j�}|jtj�5t	t
jd�5}	tjdddd|g|��ddd�ddd�y#t$rtjdddd|g|��Y�8wxYw#1swY�=xYw#1swYyxYw)N�rbr3r4�foor5)�stderrr6)	r<�assertRaisesr>�CalledProcessError�open�os�devnull�
check_callr@)r0rJr^s   r �test_runBadKeytypezKeyGenTests.test_runBadKeytypeys����;�;�=��
�
�
�z�<�<�
=�		(��b�j�j�$�'�
(�7�(��)�)�"�D�%��x�@�&�(�
(�		(�		(��)�(��)�)�#�T�5�$��A�&�(�(��
(�
(��		(�		(�sA�B1�B%�
A:�)B1�:%B"�B%�!B"�"B%�%B.	�*B1�1B:c�d�tddi�}|j|dtj�y)z�
        L{enumrepresentation} takes a dictionary as input and returns a
        dictionary with its attributes changed to enum representation.
        �format�md5-hexN)r�assertIsr�MD5_HEX�r0�optionss  r �test_enumrepresentationz#KeyGenTests.test_enumrepresentation�s-��
%�h�	�%:�;���
�
�g�h�'�);�)C�)C�Dr"c�d�tddi�}|j|dtj�y)zF
        Test for format L{FingerprintFormats.SHA256-BASE64}.
        rb�
sha256-base64N)rrdr�
SHA256_BASE64rfs  r �test_enumrepresentationsha256z)KeyGenTests.test_enumrepresentationsha256�s-��%�h��%@�A���
�
�g�h�'�);�)I�)I�Jr"c���|jt�5}tddi�ddd�|jdjj
d�y#1swY�3xYw)z9
        Test for unsupported fingerprint format
        rb�
sha-base64N�*Unsupported fingerprint format: sha-base64r)rZrrrB�	exceptionrK)r0�ems  r � test_enumrepresentationBadFormatz,KeyGenTests.test_enumrepresentationBadFormat�sY���
�
�3�
4�	9����,�7�8�	9����8�"�,�,�:K�:K�A�:N�	
�	9�	9�s�A�Ac���|j�}t|�jt�t	|dd��|j|jj�d�y)z�
        L{printFingerprint} writes a line to standard out giving the number of
        bits of the key, its fingerprint, and the basename of the file from it
        was read.
        rc�rJrbz:2048 85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:da temp
N�r<r�
setContentrrrBr,�getvalue�r0rJs  r �test_printFingerprintz!KeyGenTests.test_printFingerprint�sQ���;�;�=�����%�%�&7�8��h�)�D�E�����K�K� � �"�I�	
r"c���|j�}t|�jt�t	|dd��|j|jj�d�y)z�
        L{printFigerprint} will print key fingerprint in
        L{FingerprintFormats.SHA256-BASE64} format if explicitly specified.
        rjrtz72048 FBTCOoknq0mHy+kpfnY9tDdcAJuWtCpuQMaV3EsvbUI= temp
Nrurxs  r �test_printFingerprintsha256z'KeyGenTests.test_printFingerprintsha256�sQ��
�;�;�=�����%�%�&7�8��h�/�J�K�����K�K� � �"�F�	
r"c�"�|j�}t|�jt�|j	t
�5}t
|dd��ddd�|jdjjd�y#1swY�3xYw)zx
        L{printFigerprint} raises C{keys.BadFingerprintFormat} when unsupported
        formats are requested.
        rnrtNror)
r<rrvrrZrrrBrprK)r0rJrqs   r �)test_printFingerprintBadFingerPrintFormatz5KeyGenTests.test_printFingerprintBadFingerPrintFormat�s|��
�;�;�=�����%�%�&7�8�
�
�
�3�
4�	M���(�l�K�L�	M����8�"�,�,�:K�:K�A�:N�	
�	M�	M�s�B�Bc���|j�}t|dz�jt�t	|dd��|j|jj�d�y)zn
        L{printFingerprint} checks if the filename with the  '.pub' suffix
        exists in ~/.ssh.
        r7rcrtz>2048 85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:da temp.pub
Nrurxs  r �#test_printFingerprintSuffixAppendedz/KeyGenTests.test_printFingerprintSuffixAppended�sV��
�;�;�=����F�"�#�.�.�/@�A��h�)�D�E�����K�K� � �"�M�	
r"c�`�t|j��}|j�|jd�j}tjt�}t||ddd��|j|jj�d|�d|�d��|j|j
|jd�j�dd�|�|jtj|jd	�j��|j��y)
z�
        L{_saveKey} writes the private and public parts of a key to two
        different files and writes a report of this to standard out.
        �id_rsa�
passphraserc�rJ�passrb�&Your identification has been saved in �#
Your public key has been saved in �m.pub
The key fingerprint in <FingerprintFormats=MD5_HEX> is:
85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:da
N�
id_rsa.pub�rr<�makedirs�child�pathr�
fromStringr	rrBr,rw�
getContent�public�r0�baserJ�keys    r �test_saveKeyzKeyGenTests.test_saveKey�s���
����
�&���
�
���:�:�h�'�,�,���n�n�/�0����8�\�Y�W�X�����K�K� � �"�DL�X�
W�	
�	
����N�N�4�:�:�h�/�:�:�<�d�L�Q�SV�	
�	
����N�N�4�:�:�l�3�>�>�@�A�3�:�:�<�	
r"c�`�t|j��}|j�|jd�j}tjt�}t||ddd��|j|jj�d|�d|�d��|j|j
|jd�j�dd�|�|jtj|jd	�j��|j��y)
z�
        L{_saveKey} writes the private and public parts of a key to two
        different files and writes a report of this to standard out.
        Test with ECDSA key.
        �id_ecdsar�rcr�r�r�zm.pub
The key fingerprint in <FingerprintFormats=MD5_HEX> is:
1e:ab:83:a6:f2:04:22:99:7c:64:14:d2:ab:fa:f5:16
Nzid_ecdsa.pub)rr<r�r�r�rr�rrrBr,rwr�r�r�s    r �test_saveKeyECDSAzKeyGenTests.test_saveKeyECDSA�s�������
�&���
�
���:�:�j�)�.�.���n�n�1�2����8�\�Y�W�X�����K�K� � �"�DL�X�
W�	
�	
����N�N�4�:�:�j�1�<�<�>��l�S�UX�	
�	
����N�N�4�:�:�n�5�@�@�B�C�S�Z�Z�\�	
r"c�`�t|j��}|j�|jd�j}tjt�}t||ddd��|j|jj�d|�d|�d��|j|j
|jd�j�dd�|�|jtj|jd	�j��|j��y)
z�
        L{_saveKey} writes the private and public parts of a key to two
        different files and writes a report of this to standard out.
        Test with Ed25519 key.
        �
id_ed25519r�rcr�r�r�zm.pub
The key fingerprint in <FingerprintFormats=MD5_HEX> is:
ab:ee:c8:ed:e5:01:1b:45:b7:8d:b2:f0:8f:61:1c:14
Nzid_ed25519.pub)rr<r�r�r�rr�rrrBr,rwr�r�r�s    r �test_saveKeyEd25519zKeyGenTests.test_saveKeyEd25519s�������
�&���
�
���:�:�l�+�0�0���n�n�7�8����8�\�Y�W�X�����K�K� � �"�DL�X�
W�	
�	
����N�N�4�:�:�l�3�>�>�@�$��U��	
�	
����N�N�4�:�:�&6�7�B�B�D�E�s�z�z�|�	
r"c�`�t|j��}|j�|jd�j}tjt�}t||ddd��|j|jj�d|�d|�d��|j|j
|jd�j�dd�|�|jtj|jd	�j��|j��y)
z�
        L{_saveKey} will generate key fingerprint in
        L{FingerprintFormats.SHA256-BASE64} format if explicitly specified.
        r�r�rjr�r�r�zp.pub
The key fingerprint in <FingerprintFormats=SHA256_BASE64> is:
FBTCOoknq0mHy+kpfnY9tDdcAJuWtCpuQMaV3EsvbUI=
Nr�r�r�s    r �test_saveKeysha256zKeyGenTests.test_saveKeysha256s���
����
�&���
�
���:�:�h�'�,�,���n�n�/�0����h���X�	
�	
����K�K� � �"�AI�(�
T�	
�	
����N�N�4�:�:�h�/�:�:�<�d�L�Q�SV�	
�	
����N�N�4�:�:�l�3�>�>�@�A�3�:�:�<�	
r"c��t|j��}|j�|jd�j}tjt�}|jt�5}t||ddd��ddd�|jdjjd�y#1swY�3xYw)zq
        L{_saveKey} raises C{keys.BadFingerprintFormat} when unsupported
        formats are requested.
        r�r�rnr�Nror)rr<r�r�r�rr�r	rZrrrBrprK)r0r�rJr�rqs     r � test_saveKeyBadFingerPrintformatz,KeyGenTests.test_saveKeyBadFingerPrintformat9s���
����
�&���
�
���:�:�h�'�,�,���n�n�/�0��
�
�
�3�
4�	����%�|�|�T�
�	�
	
���8�"�,�,�:K�:K�A�:N�	
�	�	�s�3B6�6B?c�^�t|j��}|j�|jd�j}tjt�}t||ddd��|j|j
|jd�j�dd�|�y)�q
        L{_saveKey} will choose an empty string for the passphrase if
        no-passphrase is C{True}.
        r�Trc�rJz
no-passphraserbNr")rr<r�r�r�rr�r	rrBr�r�s    r �test_saveKeyEmptyPassphrasez'KeyGenTests.test_saveKeyEmptyPassphraseKs���
����
�&���
�
���:�:�h�'�,�,���n�n�/�0����h���S�	
�	
����N�N�4�:�:�h�/�:�:�<�d�C�H�#�	
r"c�\�t|j��}|j�|jd�j}tjt�}t||ddd��|j|j
|jd�j�d�|�y)r�r�Trcr�N)rr<r�r�r�rr�rrrBr�r�s    r � test_saveKeyECDSAEmptyPassphrasez,KeyGenTests.test_saveKeyECDSAEmptyPassphrase[s���
����
�&���
�
���:�:�j�)�.�.���n�n�1�2����h���S�	
�	
�������
�
�:�(>�(I�(I�(K�T�R�TW�Xr"c�\�t|j��}|j�|jd�j}tjt�}t||ddd��|j|j
|jd�j�d�|�y)r�r�Trcr�N)rr<r�r�r�rr�rrrBr�r�s    r �"test_saveKeyEd25519EmptyPassphrasez.KeyGenTests.test_saveKeyEd25519EmptyPassphraseis���
����
�&���
�
���:�:�l�+�0�0���n�n�7�8����h���S�	
�	
����N�N�4�:�:�l�3�>�>�@�$�G��	
r"c�����t|j��}|j�|jd�j�g�ddl}d�fd�}|j
|jjjd�fd��tjt�}t|dddd	�|�|jd�j�}|j|dd
�}|j||�y)zd
        When no path is specified, it will ask for the path used to store the
        key.
        �
custom_keyrNc�(���jd�y�N���append�rK�
input_promptss �r �
mock_inputz6KeyGenTests.test_saveKeyNoFilename.<locals>.mock_input������ � ��$�r"�_inputSaveFilec����Sr�)r�keyPaths �r �<lambda>z4KeyGenTests.test_saveKeyNoFilename.<locals>.<lambda>�s���g�r"Trcr�r"�rKr#r$r%)rr<r�r�r��twisted.conch.scripts.ckeygenr-�conch�scriptsr3rr�r	rr�rB)	r0r��twistedr�r��persistedKeyContent�persistedKeyr�r�s	       @@r �test_saveKeyNoFilenamez"KeyGenTests.test_saveKeyNoFilenameys����
����
�&���
�
���*�*�\�*�/�/��#%�
�,�	�	
�
�
�7�=�=�(�(�0�0�2B�DU�V��n�n�/�0������	�J��	
�#�j�j��6�A�A�C���~�~�&9�4��E������l�+r"c�P�d	d�}t|j��}|j�|jd�j}|jtjdd��tjt�}|ddd�}|jtt|||�y)
zs
        When the specified file exists, it will ask the user for confirmation
        before overwriting.
        c��dgS)N�nr�)rKs r r�z6KeyGenTests.test_saveKeyFileExists.<locals>.mock_input�s	���5�Lr"r��existsc��y)NTr�)rs r r�z4KeyGenTests.test_saveKeyFileExists.<locals>.<lambda>���r"Trcr�N)rKr#r$z	list[str])
rr<r�r�r�r-r]rr�r	rZ�
SystemExitr)r0r�r�r�r�rgs      r �test_saveKeyFileExistsz"KeyGenTests.test_saveKeyFileExists�s{��	�����
�&���
�
���*�*�\�*�/�/���
�
�2�7�7�H�n�5��n�n�/�0��&���S�����*�h��W�j�Ir"c��t|j��}|j�|jd�j}tjt�}t||dddd��|j|jj�d|�d|�d��|jd�j�}|j|j
|d	d�|�|j|jd
��|jtj|jd�j��|j��y	)zi
        L{_saveKey} can be told to write the new private key file in OpenSSH
        v1 format.
        r�r�rcrQ)rJr�rb�private-key-subtyper�r�r�N�$-----BEGIN OPENSSH PRIVATE KEY-----
r�)rr<r�r�r�rr�r	rrBr,rwr�rE�
startswithr�)r0r�rJr��privateKeyContents     r �test_saveKeySubtypeV1z!KeyGenTests.test_saveKeySubtypeV1�s��
����
�&���
�
���:�:�h�'�,�,���n�n�/�0����$�$�#�'+�	
�	
�	
����K�K� � �"�DL�X�
W�	
�!�J�J�x�0�;�;�=��������(9�4��N�PS�T�����(�(�)Q�R�	
�	
����N�N�4�:�:�l�3�>�>�@�A�3�:�:�<�	
r"c�^�|j�}tjt�}t	|�jt�td|i�|jj�jd�jd�}|j||jd��y)zl
        L{displayPublicKey} prints out the public key associated with a given
        private key.
        rJ�
�ascii�opensshN)r<rr�rrrvr	rr,rw�strip�encoderB�toString�r0rJrM�	displayeds    r �test_displayPublicKeyz!KeyGenTests.test_displayPublicKey�s���
�;�;�=����� 1�2�����%�%�&8�9��*�h�/�0��K�K�(�(�*�0�0��6�=�=�g�F�	�����F�O�O�I�$>�?r"c�`�|j�}tjt�}t	|�jt�t|dd��|jj�jd�jd�}|j||jd��y)z�
        L{displayPublicKey} prints out the public key associated with a given
        private key using the given passphrase when it's encrypted.
        �	encrypted�rJr�r�r�r�N)r<rr�rrrvr
rr,rwr�r�rBr�r�s    r �test_displayPublicKeyEncryptedz*KeyGenTests.test_displayPublicKeyEncrypted�s���
�;�;�=����� 1�2�����%�%�&B�C��h��D�E��K�K�(�(�*�0�0��6�=�=�g�F�	�����F�O�O�I�$>�?r"c��|j�}tjt�}t	|�jt�|jtdd��td|i�|jj�jd�jd�}|j||jd��y)z�
        L{displayPublicKey} prints out the public key associated with a given
        private key, asking for the passphrase when it's encrypted.
        �getpassc��y)Nr�r�)�xs r r�zLKeyGenTests.test_displayPublicKeyEncryptedPassphrasePrompt.<locals>.<lambda>�r�r"rJr�r�r�N)r<rr�rrrvr
r-r�rr,rwr�r�rBr�r�s    r �.test_displayPublicKeyEncryptedPassphrasePromptz:KeyGenTests.test_displayPublicKeyEncryptedPassphrasePrompt�s���
�;�;�=����� 1�2�����%�%�&B�C��
�
�7�I�'<�=��*�h�/�0��K�K�(�(�*�0�0��6�=�=�g�F�	�����F�O�O�I�$>�?r"c��|j�}t|�jt�|j	t
t|dd��y)z�
        L{displayPublicKey} fails with a L{BadKeyError} when trying to decrypt
        an encrypted key with the wrong password.
        �wrongr�N)r<rrvr
rZrrrxs  r �$test_displayPublicKeyWrongPassphrasez0KeyGenTests.test_displayPublicKeyWrongPassphrase�s>��
�;�;�=�����%�%�&B�C�����)��'�+R�	
r"c��tddd�}|jtd|�|j�}t	|�jt�td|i�|j|jj�jd�d�|jtt	|�j��y)zt
        L{changePassPhrase} allows a user to change the passphrase of a
        private key interactively.
        r��newpassr�rJr��;Your identification has been saved with the new passphrase.N�r(r-r�r<rrvr
rrBr,rwr��assertNotEqualr�)r0�
oldNewConfirmrJs   r �test_changePassphrasez!KeyGenTests.test_changePassphrase�s���
$�K��I�F�
��
�
�7�I�}�5��;�;�=�����%�%�&B�C��*�h�/�0�����K�K� � �"�(�(��.�I�	
�	
���(�(�8�*<�*G�*G�*I�	
r"c��tdd�}|jtd|�|j�}t	|�jt�t|dd��|j|jj�jd�d�|jtt	|�j��y)z�
        L{changePassPhrase} allows a user to change the passphrase of a
        private key, providing the old passphrase and prompting for new one.
        r�r�r�r�r�r�Nr�)r0�
newConfirmrJs   r �test_changePassphraseWithOldz(KeyGenTests.test_changePassphraseWithOld
s���
!��I�6�
��
�
�7�I�z�2��;�;�=�����%�%�&B�C��h��D�E�����K�K� � �"�(�(��.�I�	
�	
���(�(�8�*<�*G�*G�*I�	
r"c�J�|j�}t|�jt�t	|ddd��|j|jj�jd�d�|jtt|�j��y)z�
        L{changePassPhrase} allows a user to change the passphrase of a private
        key by providing both old and new passphrases without prompting.
        r��
newencrypt)rJr�r�r�r�N)r<rrvr
rrBr,rwr�r�r�rxs  r �test_changePassphraseWithBothz)KeyGenTests.test_changePassphraseWithBoth!s���
�;�;�=�����%�%�&B�C��!�;�<�P�	
�	
����K�K� � �"�(�(��.�I�	
�	
���(�(�8�*<�*G�*G�*I�	
r"c�,�|j�}t|�jt�|j	t
t|dd��}|jdt|��|jtt|�j��y)z�
        L{changePassPhrase} exits if passed an invalid old passphrase when
        trying to change the passphrase of a private key.
        r�r�z1Could not change passphrase: old passphrase errorN)
r<rrvr
rZr�rrBr%r��r0rJ�errors   r �$test_changePassphraseWrongPassphrasez0KeyGenTests.test_changePassphraseWrongPassphrase4sz��
�;�;�=�����%�%�&B�C��!�!��(�x��*Q�
��	
���?��U��	
�	
���5�x��7I�7T�7T�7V�Wr"c�j�|jtdtd��|j�}t	|�jt�|jttd|i�}|jdt|��|jtt	|�j��y)z�
        L{changePassPhrase} exits if no passphrase is specified for the
        C{getpass} call and the key is encrypted.
        r�r�rJzMCould not change passphrase: Passphrase must be provided for an encrypted keyN)
r-r�r(r<rrvr
rZr�rrBr%r�r�s   r �!test_changePassphraseEmptyGetPassz-KeyGenTests.test_changePassphraseEmptyGetPassCs���
	
�
�
�7�I�{�2��7��;�;�=�����%�%�&B�C��!�!�*�.>��X�@V�W�����
#���J�	
�
	
���5�x��7I�7T�7T�7V�Wr"c��|j�}t|�jd�|jtt
d|i�}d}|j
|t|��|j
dt|�j��y)zc
        L{changePassPhrase} exits if the file specified points to an invalid
        key.
        sfoobarrJz?Could not change passphrase: cannot guess the type of b'foobar'N)	r<rrvrZr�rrBr%r�)r0rJr��expecteds    r �test_changePassphraseBadKeyz'KeyGenTests.test_changePassphraseBadKeySss��
�;�;�=�����%�%�i�0��!�!�*�.>��X�@V�W��W������3�u�:�.�����H�X�$6�$A�$A�$C�Dr"c�b�|j�}t|�jt�dd�}|j	t
d|�|j
tt|dd��}|jdt|��|jtt|�j��y)z�
        L{changePassPhrase} doesn't modify the key file if an unexpected error
        happens when trying to create the key with the new passphrase.
        c��td��)N�oops)�RuntimeError�rK�kwargss  r r�z>KeyGenTests.test_changePassphraseCreateError.<locals>.toStringhs
���v�&�&r"r�r��rJr�z!Could not change passphrase: oopsN)rKr#r�r#r$r�r<rrvr	r-rrZr�rrBr%r�)r0rJr�r�s    r � test_changePassphraseCreateErrorz,KeyGenTests.test_changePassphraseCreateError`s���
�;�;�=�����%�%�&8�9�	'�	
�
�
�3�
�H�-��!�!���!�l�;�
��	
���<�c�%�j�I����+�X�h�-?�-J�-J�-L�Mr"c�f�|j�}t|�jt�dd�}|j	t
d|�|j
tt|dd��}d}|j|t|��|jtt|�j��y)zq
        L{changePassPhrase} doesn't modify the key file if C{toString} returns
        an empty string.
        c��yr�r�r�s  r r�zCKeyGenTests.test_changePassphraseEmptyStringError.<locals>.toStrings��r"r�r�r�z9Could not change passphrase: cannot guess the type of b''N)rKr#r�r#r$r%r�)r0rJr�r�r�s     r �%test_changePassphraseEmptyStringErrorz1KeyGenTests.test_changePassphraseEmptyStringErrorws���
�;�;�=�����%�%�&8�9�	�	
�
�
�3�
�H�-��!�!���!�l�;�
��O������3�u�:�.����+�X�h�-?�-J�-J�-L�Mr"c�,�|j�}t|�jt�|j	t
t|dd��}|jdt|��|jtt|�j��y)z�
        L{changePassPhrase} exits when trying to change the passphrase on a
        public key, and doesn't change the file.
        r�r�z.Could not change passphrase: key not encryptedN)
r<rrvrrZr�rrBr%r�r�s   r �test_changePassphrasePublicKeyz*KeyGenTests.test_changePassphrasePublicKey�sv��
�;�;�=�����%�%�&7�8��!�!��(�x�F�*S�
��	
���I�3�u�:�V����*�H�X�,>�,I�,I�,K�Lr"c���tddd�}|jtd|�|j�}t	|�jt�t|dd��|j|jj�jd�d�t	|�j�}|jt|�|j|jd��y	)
zq
        L{changePassPhrase} can be told to write the new private key file in
        OpenSSH v1 format.
        r�r�r�rQ)rJr�r�r�r�N)r(r-r�r<rrvr
rrBr,rwr�r�r�rEr�)r0r�rJr�s    r �test_changePassphraseSubtypeV1z*KeyGenTests.test_changePassphraseSubtypeV1�s���
$�K��I�F�
��
�
�7�I�}�5��;�;�=�����%�%�&B�C��h�t�L�M�����K�K� � �"�(�(��.�I�	
�%�X�.�9�9�;�����8�:K�L�����(�(�)Q�R�	
r"c�8��g�d�fd�}ddi}t||�}|j|dd�|j|jtj
j
dd���|jdt���|jdg��y)	zg
        L{options} will default to "~/.ssh/id_rsa" if the user doesn't
        specify a key.
        c�(���jd�yr�r�r�s �r r�z5KeyGenTests.test_useDefaultForKey.<locals>.mock_input�r�r"rJr�z.sshr��Nr�)rrBrE�endswithr]r��join�len)r0r�rgrJr�s    @r �test_useDefaultForKeyz!KeyGenTests.test_useDefaultForKey�s����
$&�
�	��r�"��#�G�Z�8������J���	
�
	
����)�)�"�'�'�,�,�v�x�*H�I�J�	
����C�
�.�/����"��}�-r"c��ddi}|jtt|�}|jd|jd�y)z�
        Ensure FileNotFoundError is handled, whether the user has supplied
        a bad path, or has no key at the default path.
        rJ�/foo/bar�+could not be opened, please specify a file.rN)rZr�r�assertInrK�r0rg�excs   r �'test_displayPublicKeyHandleFileNotFoundz3KeyGenTests.test_displayPublicKeyHandleFileNotFound�s:��
�z�*�����
�,<�g�F���
�
�C�S�X�X�a�[�Qr"c��ddi}|jtt|�}|jd|jd�y)�N
        Ensure FileNotFoundError is handled for an invalid filename.
        rJrrrN)rZr�rrrKrs   r �'test_changePassPhraseHandleFileNotFoundz3KeyGenTests.test_changePassPhraseHandleFileNotFound�s:���z�*�����
�,<�g�F���
�
�C�S�X�X�a�[�Qr"c��ddd�}|jtt|�}|jd|jd�y)rrrcrtrrN)rZr�rrrKrs   r �'test_printFingerprintHandleFileNotFoundz3KeyGenTests.test_printFingerprintHandleFileNotFound�s:�� *�Y�?�����
�,<�g�F���
�
�C�S�X�X�a�[�Qr")r$�None)NN)rGr%rH�
str | NonerIrr$r),�__name__�
__module__�__qualname__�__doc__r1rNrUr`rhrlrrryr{r}rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrr�r"r r*r*Cs���/�#�(,�	+��+��+�&�	+�

�+�6
5�(�E�K�
�
�
�
�
�
�0
�2
�4
�4
�$
� Y�
� ,�8J�$ 
�D
@�
@�@�	
�
�(
�(
�&
X�X� E�N�.N�0M�
�,.�2R�R�Rr"r*)r'r%r$zCallable[[object], str])'r �
__future__rr�r]r>r.�ior�typingrr�twisted.conch.test.keydatarrr	r
r�twisted.python.filepathr�twisted.python.reflectr
�twisted.trial.unittestrr�rrrrrr�twisted.conch.ssh.keysrrrr�skipr(r*r�r"r �<module>r*su���#��	��
�	������-�0�+��� �����E�D��$_
R�(�_
Rr"

Zerion Mini Shell 1.0