From: Daniel Garcia Moreno Date: Sun, 1 Sep 2013 08:03:10 +0000 (+0200) Subject: Fixed aes deltatar restoring X-Git-Tag: v2.2~107 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=04fb06f49f347319b975be4f5edd196a970bae6a;p=python-delta-tar Fixed aes deltatar restoring Test DeltaTarGzipAes256ConcatTest.test_restore_from_index_diff_backup3 was failing and this patch fixed it. The encryption was initialized on every call to _init_read_gz and every time we found a new encryption chunk (something that starts with "Salted__"). The correct way to do it is to initialize at the beginning and every time we find a new encryption chunk, it's not needed to initialize the encryption on every call to _init_read_gz. There was an exception trying to decompress a chunk of data in the line: buf = self.cmp.decompress(buf) This happened because at the end of the file the call to _init_read_gz fails and the exception is controlled by a try-except, but sometimes just after this fail there is a call to read the trailing data with the gzip and a try to decompress and it fails because the self.cmp is not initialized, this data is garbage, so I catch this exception and everything works okay. --- diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index ede5175..e93ef1f 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -447,6 +447,9 @@ class _Stream: raise CompressionError("zlib module is not available") self.zlib = zlib if mode == "r": + if self.enctype == 'aes': + self.encryption = aescrypto.AESCrypt(self.password, + key_length=self.key_length) self._init_read_gz() else: self._init_write_gz() @@ -527,7 +530,6 @@ class _Stream: self.__write_to_file(self.encryption.salt_str) elif set_last_block_offset: self.last_block_offset = self.fileobj.tell() - self.fileobj timestamp = struct.pack("