%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/duplicity/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/duplicity/__pycache__/gpg.cpython-312.pyc

�

�2e�C����dZddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddlm
Z
ddlmZddlm
Z
dd	lmZd
ZGd�de�ZGd
�de�ZGd�de�Zdd�Zdd�Zdd�Zdd�Zy)z�
duplicity's gpg interface, builds upon Frank Tobin's GnuPGInterface
which is now patched with some code for iterative threaded execution
see duplicity's README for details
�N)�config)�gpginterface)�log)�tempdir)�util)�sha1)�md5ic��eZdZdZy)�GPGErrorz!
    Indicate some GPG Error
    N)�__name__�
__module__�__qualname__�__doc__���//usr/lib/python3/dist-packages/duplicity/gpg.pyrr.s���	rrc�F�eZdZdZdd�ZejZed�Zd�Z	y)�
GPGProfilezF
    Just hold some GPG settings, avoid passing tons of arguments
    Nc�8�|�t|t�sJ�||_||_||_d|_|�t|t�sJ�||_ng|_|�t|t�sJ�||_ng|_|jtj�|_y)a>
        Set all data with initializer

        passphrase is the passphrase.  If it is None (not ""), assume
        it hasn't been set.  sign_key can be blank if no signing is
        indicated, and recipients should be a list of keys.  For all
        keys, the format should be an hex key like 'AA0E73D2'.
        N)
�
isinstance�str�
passphrase�signing_passphrase�sign_key�encrypt_secring�list�
recipients�hidden_recipients�get_gpg_versionr�
gpg_binary�gpg_version)�selfrrrrs     r�__init__zGPGProfile.__init__;s����!�Z�
�C�%@�@�@�$���",��� ��
�#����!��j�$�/�/�/�(�D�O� �D�O��(��/��6�6�6�%6�D�"�%'�D�"��/�/��0A�0A�B��rsU^gpg.*\(GnuPG(?:/MacGPG2)?\) (?P<maj>[0-9]+)\.(?P<min>[0-9]+)\.(?P<bug>[0-9]+)(-.+)?$c�b�tj�}|�||_tjrHtjj�D]'}|jjj|��)|jdgdg��}|jdj�j�}|jj|�}|�Mt|j!d��t|j!d��t|j!d��fSt#d|�d|����)	Nz	--version�stdout)�
create_fhs�maj�min�bugz%failed to determine gnupg version of z from )r�GnuPG�callr�gpg_options�split�options�
extra_args�append�run�handles�readline�rstrip�_version_re�search�int�groupr)r"�binary�gnupg�opt�res�line�ms       rrzGPGProfile.get_gpg_version[s����"�"�$�����E�J�����)�)�/�/�1�
5���
�
�(�(�/�/��4�
5��i�i��
�8�*�i�=���{�{�8�$�-�-�/�6�6�8�����#�#�D�)���=��q�w�w�u�~�&��A�G�G�E�N�(;�S������=P�P�P��>�v�h�f�T�F�S�T�Tr)NNNN)
rr
rrr#�re�compile�rcr5rrrrrr6s)���C�:
���B��q�r�K�Urrc�H�eZdZdZd�Zdd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)
�GPGFilezI
    File-like object that encrypts decrypts another file on the fly
    c�
�d|_d|_tjt	j
�j
���|_||_d|_	d|_
tj�}tj�tj|_d|j _|j j$j'd�|j j$j'd�|j(dddk(r6tj*r�|j j$j'd�ns|j(dd	d
k(rn`|j(dd	dk\r6tj*s>|j j$j'd�nt-d
|j(����tj.rHtj.j1�D]'}|j j$j'|��)g}|j2r,|j2|j _|j'd�|r%|j2r|j6r
|j6}n|j8}|�d}|�rx|j:r|j:|j _|j<r|j<|j _|j:s|j<r|j'd�n|j'd�|j j$j'd�tj*rdg}nddg}tj>s|j'd�|jA|||jCd�|jd���}	tj*s;|	jDdjG|�|	jDdjI�|	jDd|_%�nP|j:s|j<r8|jLr,|j'd�|j'|jL�|jCd�|jd�}
|j2rJtjt	j
�j
���|_|j|
d<tj*rdg}nddg}|jAdg||
��}	tj*s;|	jDdjG|�|	jDdjI�|	jDd|_'|	|_(||_)y)a�
        GPGFile initializer

        If recipients is set, use public key encryption and encrypt to
        the given keys.  Otherwise, use symmetric encryption.

        encrypt_path is the Path of the gpg encrypted file.  Right now
        only symmetric encryption/decryption is supported.

        If passphrase is false, do not set passphrase - GPG program
        should prompt for it.
        N)�dirrz--no-secmem-warningz--ignore-mdc-error��rFz--use-agent�)rHr)rHrFz--pinentry-mode=loopbackzUnsupported GNUPG version, z--sign�z	--encryptz--symmetricz--force-mdc�stdinrz--compress-algo=none�wb)r%�stderr)r&�
attach_fhsz--secret-keyring�rb)rJrL�statusr%z	--decrypt)*�	status_fp�closed�tempfile�
TemporaryFiler�defaultrE�	stderr_fp�name�
byte_count�	signaturerr*rr r+r.�meta_interactiver/r0r!�	use_agentrr,r-r�default_keyrrrr�compressionr1�openr2�write�close�	gpg_inputr�
gpg_output�gpg_process�encrypt)r"rc�encrypt_path�profiler:r;�cmdlistr�	gnupg_fhs�p1�
gpg_attachs           rr#zGPGFile.__init__ss8��������!�/�/�G�O�O�4E�4I�4I�4K�L��� ��	��������"�"�$�����(��*�*�E�J�)*��
�
�&�
�
�
� � �'�'�(=�>�
�
�
� � �'�'�(<�=����r��"�d�*�����
�
�(�(�/�/�
�>�
�
 �
 ��!�
$��
.��
�
 �
 ��!�
$��
.��#�#��
�
�(�(�/�/�0J�K��8��9L�9L�8M�N�O�O�����)�)�/�/�1�
5���
�
�(�(�/�/��4�
5������(/�(8�(8�E�M�M�%��N�N�8�$��w�'�'�G�,F�,F� �3�3�J� �+�+�J����J���!�!�+2�+=�+=��
�
�(��(�(�29�2K�2K��
�
�/��!�!�W�%>�%>����{�+����}�-��M�M�$�$�+�+�M�:������	�%�l�3�	��%�%����5�6�����$�*�/�/��5�"�n�n����B��#�#��
�
�<�(�.�.�z�:��
�
�<�(�.�.�0��Z�Z��0�D�N��"�"�g�&?�&?�W�E\�E\����1�2����w�6�6�7�#/�#4�#4�T�#:�d�n�n�U�J����!)�!7�!7�G�O�O�<M�<Q�<Q�<S�!T���'+�~�~�
�8�$������	�&�|�4�	����K�=�Y�:��V�B��#�#��
�
�<�(�.�.�z�:��
�
�<�(�.�.�0� �j�j��2�D�O������rc��	|jj|�}|�|xjt|�z
c_|S#t$r|j�YSwxYw�N)ra�readrW�len�	Exception�
gpg_failed)r"�lengthr<s   rrlzGPGFile.read�sY��	��/�/�&�&�v�.�C������3�s�8�+���
���	��O�O���
�	�s�;?�A�Ac��	|jj|�}|�|xj|z
c_|S#t$r|j	�YSwxYwrk)r`r^rWrnro)r"�bufr<s   rr^z
GPGFile.write�sU��	��.�.�&�&�s�+�C������3�&���
���	��O�O���
�	�s�26�A�Ac��|jSrk)rW�r"s r�tellzGPGFile.tells�����rc���|jrJ�||jk\s(Jt|��dt|j�����||jkDr|j||jz
�yy)Nz < )rcrWr7rl)r"�offsets  r�seekzGPGFile.seekse���<�<�������(�S�S��[�M��S����=Q�<R�*S�S�(��D�O�O�#��I�I�f�t���.�/�$rc�r�d}|dz
}|jjd�|jD]6}	|t|j�t	j
�d��d�z
}�8|dz
}|jd�dkDst|��y	#t$r }||j��d�z
}Yd}~��d}~wwxYw)
NzGPG Failed, see log below:
z===== Begin GnuPG log =====
r�replace�
z===== End GnuPG log =====
zinvalid packet (ctb=14)���rI)	rUrxr�strip�locale�getpreferredencodingrn�findr)r"�msgr=�es    rrozGPGFile.gpg_failed
s���,���.�.�������A���N�N�	+�D�
+��#�d�j�j�l�F�,G�,G�,I�:�V�W�WY�Z�Z��	+�
	�,�,�����2�3�b�8��3�-����
�
+��$�*�*�,��r�*�*���
+�s�3B
�
	B6�B1�1B6c�,�|jrS	|jj�|j
r|j
�	|jj�nyd}|r#	|jjt�}|r�#	|jj�|j
r|j
�	|jj�|jj�d|_
y#t$r|j	�Y��wxYw#t$r|j	�Y�\wxYw#t$r|j	�Y��wxYw#t$r|j	�Y��wxYw#t$r|j	�Y��wxYw)NrF)rcr`r_rnrorP�
set_signaturerb�waitrarl�	blocksizerUrQ)r"r<s  rr_z
GPGFile.closesO���<�<�
"����$�$�&��~�~��"�"�$�
"�� � �%�%�'��C��&��/�/�.�.�y�9�C��
"����%�%�'��~�~��"�"�$�
"�� � �%�%�'�	
����������7�
"����!�
"���
"����!�
"��!�&��O�O�%�&���
"����!�
"���
"����!�
"�sY�C;�D�%D9�E�?E7�;D�D�D6�5D6�9E�E�E4�3E4�7F�Fc�R�|jjd�|jj�}tjd|tj
�}|sd|_yt|jd��dk\sJ�|jd�j�|_y)z�
        Set self.signature to signature keyID

        This only applies to decrypted files.  If the file was not
        signed, set self.signature to None.
        rsGOODSIG ([0-9A-F]*)NrF�)
rPrxrlr?r6�MrXrmr8�decode)r"�
status_buf�matchs   rr�zGPGFile.set_signature:s|��	
�����A���^�^�(�(�*�
��	�	�0�*�b�d�d�C���!�D�N��u�{�{�1�~�&�!�+�+�+�"�[�[��^�2�2�4�D�Nrc�6�|jsJ�|jS)z=
        Return  keyID of signature, or None if none
        )rQrXrts r�
get_signaturezGPGFile.get_signatureJs���{�{��{��~�~�rN)r|)
rr
rrr#rlr^rurxror_r�r�rrrrCrCns7���z�x���0�
��B5� rrCc	�l��ddlm}�fd�}�fd�}|dz
}||z
}	td|j��|�}
d}		|	|�z
}||j	�krn-	|j�j}
|
j
��K|
j|j��|s|�}||kr|||z
|
�|
j�|S#t$rd}Y�Xt$r.}tjd��d	t|����Yd
}~��d
}~wwxYw#t$r|
j��wxYw)aJ
    Write GPG compressed file of given size

    This function writes a gpg compressed file by reading from the
    input iter and writing to filename.  When it has read an amount
    close to the size limit, it "tops off" the incoming data with
    incompressible data, to try to hit the limit exactly.

    block_iter should have methods .next(size), which returns the next
    block of data, which should be at most size bytes long.  Also
    .get_footer() returns a string to write at the end of the input
    file.  The footer should have max length max_footer_size.

    Because gpg uses compression, we don't assume that putting
    bytes_in bytes into gpg will result in bytes_out = bytes_in out.
    However, do assume that bytes_out <= bytes_in approximately.

    Returns true if succeeded in writing until end of block_iter.
    r)�pathc���t�d�}tj||j|�|k(sJ�|j	�y)z�
        Add bytelen of incompressible data to to_gpg_fp

        In this case we take the incompressible data from the
        beginning of filename (it should contain enough because size
        >> largest block size).
        rNN)r]r�copyfileobjr`r_)�bytelen�file�incompressible_fp�filenames   �r�top_offzGPGWriteFile.<locals>.top_offjs@���!��4�0����� 1�4�>�>�7�K�w�V�V�V����!rc�B��tj��jSrk)�os�stat�st_size)r�s�r�get_current_sizez&GPGWriteFile.<locals>.get_current_sizevs����w�w�x� �(�(�(ri�TrFzRead error on z: N)�	duplicityr�rC�Path�
get_read_size�__next__�data�
StopIterationrnr�
FatalErrorrr^�
get_footerr_)�
block_iterr�re�size�max_footer_sizer�r�r��target_size�	data_sizer��at_end_of_blockiter�bytes_to_gor�r��cursizes `              r�GPGWriteFiler�RsE���,�
"�)���"�K��o�-�I��4����8�,�g�6�D�����#�&6�&8�8�K��Z�5�5�7�7��
F�!�*�*�,�1�1��
�J�J�t���	
�
�
�:�(�(�*�+�"�&�(�G���$���g�-�t�4��
�
��"�"��!�
�&'�#���
F������z��C��F�8�D�E�E��
F�����
�
��
��sB�D�C�5AD�D�D�D�'$D�D�D�D�D3c��Gd�dt�}|t|d��}|rtjddd|�}n|}d}	||jz
}||j�krn(	t
|�}	|j|	j��K|j�s|j�rJ�|S#t$rd}Y�1wxYw)a�
    Write gzipped compressed file of given size

    This is like the earlier GPGWriteFile except it writes a gzipped
    file instead of a gpg'd file.  This function is somewhat out of
    place, because it doesn't deal with GPG at all, but it is very
    similar to GPGWriteFile so they might as well be defined together.

    The input requirements on block_iter and the output is the same as
    GPGWriteFile (returns true if wrote until end of block_iter).
    c�"�eZdZdZd�Zd�Zd�Zy)�"GzipWriteFile.<locals>.FileCountedzP
        Wrapper around file object that counts number of bytes written
        c� �||_d|_y)Nr)�fileobjrW)r"r�s  rr#z+GzipWriteFile.<locals>.FileCounted.__init__�s��"�D�L��D�Orc�x�|jj|�}|xjt|�z
c_|Srk)r�r^rWrm)r"rr�results   rr^z(GzipWriteFile.<locals>.FileCounted.write�s-���\�\�'�'��,�F��O�O�s�3�x�'�O��Mrc�6�|jj�Srk)r�r_rts rr_z(GzipWriteFile.<locals>.FileCounted.close�s���<�<�%�%�'�'rN)rr
rrr#r^r_rrr�FileCountedr��s��	�	 �	�
	(rr�rKN�rrF)�objectr]�gzip�GzipFilerWr��nextr�r^r�r_)
r�r�r��gzippedr��file_counted�outfiler�r��	new_blocks
          r�
GzipWriteFiler��s���(�f�(�"�t�H�d�3�4�L���-�-��d�A�|�<������
��\�4�4�4����1�1�3�3��	��Z�(�I�	�
�
�i�n�n�%���}�}��|�'9�'9�';�;�;����
�	�"#���	�s�&B1�1B?�>B?c��t||||�S)a�
    Write plain uncompressed file of given size

    This is like the earlier GPGWriteFile except it writes a gzipped
    file instead of a gpg'd file.  This function is somewhat out of
    place, because it doesn't deal with GPG at all, but it is very
    similar to GPGWriteFile so they might as well be defined together.

    The input requirements on block_iter and the output is the same as
    GPGWriteFile (returns true if wrote until end of block_iter).
    )r�)r�r�r�r�s    r�PlainWriteFiler��s����X�t�W�=�=rc�6�|jd�}|dk(rt�}n|dk(rt�}n
Jd|����	|jt�}|sn|j|��*|j
�rJ�|r|j�S|j�S)z�
    Return hash of path

    hash should be "MD5" or "SHA1".  The output will be in hexadecimal
    form if hex is true, and in text (base64) otherwise.
    rN�SHA1�MD5z
Unknown hash )	r]rr	rlr��updater_�	hexdigest�digest)�hashr��hex�fp�hash_objrrs      r�get_hashr��s���
���4��B��v�~��6��	
����5��(�M�$��(�(�q�
��g�g�i� ���������	�
�x�x�z��>�
��!�!�#�#���� � r)��i@)r�T)r�FrG)rr�r~r�r?rRr�rrrrr�hashlibrr	r�rnrr�rrCr�r�r�r�rrr�<module>r�sv��,��
�	�	���"�������	�	�y�	�5U��5U�pa�f�a�HD�N2�j>�!r

Zerion Mini Shell 1.0