3 M(YA@sLdZddlZddlmZmZmZmZddlmZddZ ddZ ddgZ dS) a_Large file support .. deprecated:: 3.4 The VARBLOCK format is NOT recommended for general use, has been deprecated since Python-RSA 3.4, and will be removed in a future release. It's vulnerable to a number of attacks: 1. decrypt/encrypt_bigfile() does not implement `Authenticated encryption`_ nor uses MACs to verify messages before decrypting public key encrypted messages. 2. decrypt/encrypt_bigfile() does not use hybrid encryption (it uses plain RSA) and has no method for chaining, so block reordering is possible. See `issue #19 on Github`_ for more information. .. _Authenticated encryption: https://en.wikipedia.org/wiki/Authenticated_encryption .. _issue #19 on Github: https://github.com/sybrenstuvel/python-rsa/issues/13 This module contains functions to: - break a file into smaller blocks, and encrypt them, and store the encrypted blocks in another file. - take such an encrypted files, decrypt its blocks, and reconstruct the original file. The encrypted file format is as follows, where || denotes byte concatenation: FILE := VERSION || BLOCK || BLOCK ... BLOCK := LENGTH || DATA LENGTH := varint-encoded length of the subsequent data. Varint comes from Google Protobuf, and encodes an integer into a variable number of bytes. Each byte uses the 7 lowest bits to encode the value. The highest bit set to 1 indicates the next byte is also part of the varint. The last byte will have this bit set to 0. This file format is called the VARBLOCK format, in line with the varint format used to denote the block sizes. N)keycommonpkcs1varblock)bytecCstjdtddt|tjs(td|tj|j d}|d}|j t t j x:t j||D]*}tj||}t j|t||j |q^WdS)a&Encrypts a file, writing it to 'outfile' in VARBLOCK format. .. deprecated:: 3.4 This function was deprecated in Python-RSA version 3.4 due to security issues in the VARBLOCK format. See the documentation_ for more information. .. _documentation: https://stuvel.eu/python-rsa-doc/usage.html#working-with-big-files :param infile: file-like object to read the cleartext from :param outfile: file-like object to write the crypto in VARBLOCK format to :param pub_key: :py:class:`rsa.PublicKey` to encrypt with zThe 'rsa.bigfile.encrypt_bigfile' function was deprecated in Python-RSA version 3.4 due to security issues in the VARBLOCK format. See https://stuvel.eu/python-rsa-doc/usage.html#working-with-big-files for more information.) stacklevelzPublic key required, but got %r N)warningswarnDeprecationWarning isinstancerZ PublicKey TypeErrorrZbit_sizenwriterrZVARBLOCK_VERSIONZyield_fixedblocksrZencryptZ write_varintlen)infileoutfileZpub_keyZ key_bytes blocksizeblockZcryptor2/private/tmp/pip-build-nl73fm5q/rsa/rsa/bigfile.pyencrypt_bigfileDs    rcCsVtjdtddt|tjs(td|x(tj|D]}t j ||}|j |q4WdS)a(Decrypts an encrypted VARBLOCK file, writing it to 'outfile' .. deprecated:: 3.4 This function was deprecated in Python-RSA version 3.4 due to security issues in the VARBLOCK format. See the documentation_ for more information. .. _documentation: https://stuvel.eu/python-rsa-doc/usage.html#working-with-big-files :param infile: file-like object to read the crypto in VARBLOCK format from :param outfile: file-like object to write the cleartext to :param priv_key: :py:class:`rsa.PrivateKey` to decrypt with zThe 'rsa.bigfile.decrypt_bigfile' function was deprecated in Python-RSA version 3.4 due to security issues in the VARBLOCK format. See https://stuvel.eu/python-rsa-doc/usage.html#working-with-big-files for more information.r)rz Private key required, but got %rN) r r r rrZ PrivateKeyrrZyield_varblocksrZdecryptr)rrZpriv_keyrZ cleartextrrrdecrypt_bigfilejs    r) __doc__r ZrsarrrrZ rsa._compatrrr__all__rrrr<s  &