\x20\40\x20\40 HEX
HEX
Server: Apache
System: Linux web1.jenscom.net 4.18.0-553.111.1.el8_10.x86_64 #1 SMP Sun Mar 8 20:06:07 EDT 2026 x86_64
User: sps (1059)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: //usr/lib64/python3.6/site-packages/borg/crypto/__pycache__/file_integrity.cpython-36.opt-1.pyc
3

y��b �@s�ddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZe	�ZGdd�d�ZGd	d
�d
e�Z
Gdd�de
�ZGd
d�de
�ZejeejeiZGdd�de�ZGdd�de�ZGdd�de�ZdS)�N)�compare_digest�)�IntegrityError)�
create_logger)�StreamingXXH64c@sTeZdZdd�Zdd�Zdd�Zejfdd�Zd	d
�Z	ddd
�Z
dd�Zdd�ZdS)�FileLikeWrappercCs|jj�|S)N)�fd�	__enter__)�self�r�&/usr/lib64/python3.6/file_integrity.pyr	s
zFileLikeWrapper.__enter__cCs|jj|||�dS)N)r�__exit__)r
�exc_type�exc_val�exc_tbrrrr
szFileLikeWrapper.__exit__cCs
|jj�S)N)r�tell)r
rrrrszFileLikeWrapper.tellcCs|jj||�S)N)r�seek)r
�offset�whencerrrrszFileLikeWrapper.seekcCs|jj|�S)N)r�write)r
�datarrrrszFileLikeWrapper.writeNcCs|jj|�S)N)r�read)r
�nrrrrszFileLikeWrapper.readcCs|jj�dS)N)r�flush)r
rrrr"szFileLikeWrapper.flushcCs
|jj�S)N)r�fileno)r
rrrr%szFileLikeWrapper.fileno)N)
�__name__�
__module__�__qualname__r	r
r�io�SEEK_SETrrrrrrrrrrs
rcsjeZdZdZdZdZdd�Z�fdd�Z�fdd�Zd�fd	d
�	Z	dd�Z
ed
�dd�Zddd�Z
�ZS)�FileHashingWrappera'
    Wrapper for file-like objects that computes a hash on-the-fly while reading/writing.

    WARNING: Seeks should only be used to query the size of the file, not
    to skip data, because skipped data isn't read and not hashed into the digest.

    Similarly skipping while writing to create sparse files is also not supported.

    Data has to be read/written in a symmetric fashion, otherwise different
    digests will be generated.

    Note: When used as a context manager read/write operations outside the enclosed scope
    are illegal.
    NcCs||_||_|j�|_dS)N)r�writing�FACTORY�hash)r
�
backing_fdrrrr�__init__<szFileHashingWrapper.__init__cs$|dkr|j�t�j|||�dS)N)�hash_length�superr
)r
rrr)�	__class__rrr
AszFileHashingWrapper.__exit__cst�j|�}|jj|�|S)zI
        Write *data* to backing file and update internal state.
        )r'rr#�update)r
rr)r(rrrFszFileHashingWrapper.writecst�j|�}|jj|�|S)zf
        Read *data* from backing file (*n* has the usual meaning) and update internal state.
        )r'rr#r))r
rr)r(rrrNszFileHashingWrapper.readcCs
|jj�S)zn
        Return current digest bytes as hex-string.

        Note: this can be called multiple times.
        )r#�	hexdigest)r
rrrr*VszFileHashingWrapper.hexdigest)rcCs|jj|�dS)N)r#r))r
rrrrr)^szFileHashingWrapper.updateFcCs.|r|jdtj�|jjt|j��j��dS)Nr)rr�SEEK_ENDr#r)�strr�encode)r
�seek_to_endrrrr&aszFileHashingWrapper.hash_length)N)F)rrr�__doc__�	ALGORITHMr"r%r
rrr*�bytesr)r&�
__classcell__rr)r(rr )sr c@seZdZdZejZdS)�SHA512FileHashingWrapperZSHA512N)rrrr0�hashlibZsha512r"rrrrr3hsr3c@seZdZdZeZdS)�XXH64FileHashingWrapperZXXH64N)rrrr0rr"rrrrr5msr5c@seZdZdZdS)�FileIntegrityErrorzFile failed integrity check: {}N)rrrr/rrrrr6xsr6c@s\eZdZddd�Zdd�Zddd�Zeeed�d	d
��Zddd
�Z	dd�Z
ed�dd�ZdS)�IntegrityCheckedFileNc
Cs|||_||_|rdnd}|p$t||�|_i|_t}|sX|j||�}|rX|\}	|_t|	}||j|d�|_|_	|j
|�dS)N�wb�rb)r$r)�pathr!�openZfile_fd�digestsr5�load_integrity_data�SUPPORTED_ALGORITHMSr�hasher�
hash_filename)
r
r:r�filename�override_fd�integrity_data�modeZhash_clsZalgorithm_and_digests�	algorithmrrrr%}s
zIntegrityCheckedFile.__init__cCs|dk	r|j||�SdS)N)�parse_integrity_data)r
r:rCrrrr=�sz(IntegrityCheckedFile.load_integrity_datacCs>tjj|p|j�}|jjdt|�j��|jj|j��dS)Nz%10d)�osr:�basenamer?r)�lenr-)r
rArrrr@�sz"IntegrityCheckedFile.hash_filename)r:rcCs�yDtj|�}|d}|tkr.tjd||�dS|d}|d||fStttfk
r�}ztjd||�t|��WYdd}~XnXdS)NrEz3Cannot verify integrity of %s: Unknown algorithm %rr<�finalz)Could not parse integrity data for %s: %s)	�json�loadsr>�logger�warning�
ValueError�	TypeError�KeyErrorr6)�clsr:rrCrEr<�errrrF�s
z)IntegrityCheckedFile.parse_integrity_dataFcCs�|jr|jrdS|jjdt|�j��|jj|j��|jj|d�|jj�}|jrf||j|<n&|jr�t|jj	|d�|�r�t
|j��dS)Nz%10d)r.�)r!r<r?r)rIr-r&r*r�getr6r:)r
Zpartname�is_finalZdigestrrr�	hash_part�s
zIntegrityCheckedFile.hash_partcCsn|dk	}|s|jddd�|jj|||�|r2dS|jrV|jtj|jj|jd���n|jrjt	j
d|j�dS)NrJT)rV)rEr<zVerified integrity of %s)rWr?r
r!�store_integrity_datarK�dumpsr0r<rM�debugr:)r
rrrZ	exceptionrrrr
�szIntegrityCheckedFile.__exit__)rcCs
||_dS)N)rC)r
rrrrrX�sz)IntegrityCheckedFile.store_integrity_data)NNN)N)F)rrrr%r=r@�classmethodr,rFrWr
rXrrrrr7|s


r7csLeZdZd
�fdd�	Zdd�Zedd��Zedd	��Ze	d
�dd�Z
�ZS)�DetachedIntegrityCheckedFileNcsHt�j||||�|p tjj|�}tjj|�}|jtjj||��|_dS)N)	r'r%rGr:rH�dirname�integrity_file_path�join�output_integrity_file)r
r:rrArBZ
output_dir)r(rrr%�sz%DetachedIntegrityCheckedFile.__init__cCs|j|j�S)N)�read_integrity_filer:)r
r:rCrrrr=�sz0DetachedIntegrityCheckedFile.load_integrity_datacCs|dS)Nz
.integrityr)r:rrrr^�sz0DetachedIntegrityCheckedFile.integrity_file_pathcCs�y,t|j|�d��}|j||j��SQRXWnVtk
rLtjd|�Yn8tk
r�}ztjd||�t	|��WYdd}~XnXdS)N�rzNo integrity file found for %sz(Could not read integrity file for %s: %s)
r;r^rFr�FileNotFoundErrorrM�info�OSErrorrNr6)rRr:rrSrrrra�sz0DetachedIntegrityCheckedFile.read_integrity_file)rc	Cs&t|jd��}|j|�WdQRXdS)N�w)r;r`r)r
rrrrrrX�sz1DetachedIntegrityCheckedFile.store_integrity_data)NN)rrrr%r=�staticmethodr^r[rar,rXr2rr)r(rr\�s
r\)r4rrKrGZhmacrZhelpersrrMrZalgorithms.checksumsrrr r3r5r0r>r6r7r\rrrr�<module>s"?
U