1414# See the License for the specific language governing permissions and
1515# limitations under the License.
1616
17- ''' Large file support
17+ """ Large file support
1818
1919 - break a file into smaller blocks, and encrypt them, and store the
2020 encrypted blocks in another file.
3737This file format is called the VARBLOCK format, in line with the varint format
3838used to denote the block sizes.
3939
40- '''
40+ """
4141
4242from rsa import key , common , pkcs1 , varblock
4343from rsa ._compat import byte
4444
45+
4546def encrypt_bigfile (infile , outfile , pub_key ):
46- ''' Encrypts a file, writing it to 'outfile' in VARBLOCK format.
47-
47+ """ Encrypts a file, writing it to 'outfile' in VARBLOCK format.
48+
4849 :param infile: file-like object to read the cleartext from
4950 :param outfile: file-like object to write the crypto in VARBLOCK format to
5051 :param pub_key: :py:class:`rsa.PublicKey` to encrypt with
5152
52- '''
53+ """
5354
5455 if not isinstance (pub_key , key .PublicKey ):
5556 raise TypeError ('Public key required, but got %r' % pub_key )
5657
5758 key_bytes = common .bit_size (pub_key .n ) // 8
58- blocksize = key_bytes - 11 # keep space for PKCS#1 padding
59+ blocksize = key_bytes - 11 # keep space for PKCS#1 padding
5960
6061 # Write the version number to the VARBLOCK file
6162 outfile .write (byte (varblock .VARBLOCK_VERSION ))
@@ -67,21 +68,22 @@ def encrypt_bigfile(infile, outfile, pub_key):
6768 varblock .write_varint (outfile , len (crypto ))
6869 outfile .write (crypto )
6970
71+
7072def decrypt_bigfile (infile , outfile , priv_key ):
71- ''' Decrypts an encrypted VARBLOCK file, writing it to 'outfile'
72-
73+ """ Decrypts an encrypted VARBLOCK file, writing it to 'outfile'
74+
7375 :param infile: file-like object to read the crypto in VARBLOCK format from
7476 :param outfile: file-like object to write the cleartext to
7577 :param priv_key: :py:class:`rsa.PrivateKey` to decrypt with
7678
77- '''
79+ """
7880
7981 if not isinstance (priv_key , key .PrivateKey ):
8082 raise TypeError ('Private key required, but got %r' % priv_key )
81-
83+
8284 for block in varblock .yield_varblocks (infile ):
8385 cleartext = pkcs1 .decrypt (block , priv_key )
8486 outfile .write (cleartext )
8587
86- __all__ = ['encrypt_bigfile' , 'decrypt_bigfile' ]
8788
89+ __all__ = ['encrypt_bigfile' , 'decrypt_bigfile' ]
0 commit comments