self.salt = Random.new().read(self.bs - len('Salted__'))
self.password = password
- self.get_pad = self.get_pkcs5_pad
- self.split_pad = self.split_pkcs5_pad
+ self.get_pad = self.get_random_pad
+ self.split_pad = self.split_random_pad
def init(self):
'''
def __dec_read(self, size):
buf = self.fileobj.read(size)
+ last = len(buf) < size
if self.enctype == 'aes':
- buf = self.__split_enc_file(buf)
+ buf = self.__split_enc_file(buf, last)
return buf
- def __split_enc_file(self, buf):
+ def __split_enc_file(self, buf, last):
+ if not buf:
+ return buf
+
try:
idx = buf.index('Salted__')
except ValueError:
- buf = self.encryption.decrypt(buf)
+ buf = self.encryption.decrypt(buf, last)
else:
b1 = buf[:idx]
b2 = buf[idx:]
self.encryption.get_salt_str(b2)
self.encryption.init()
b2 = b2[len(self.encryption.salt_str):]
- buf += self.__split_enc_file(b2)
+ buf += self.__split_enc_file(b2, last)
return buf
# class _Stream
assert os.path.exists("sample.tar.gz.aes.0") # beginning of the tar file
assert os.path.exists("sample.tar.gz.aes.1") # first file
- os.system("openssl aes-128-cbc -k 'key' -d -in sample.tar.gz.aes.1 -out sample.tar.gz")
- os.system("zcat sample.tar.gz > sample.tar")
+ os.system("openssl aes-128-cbc -nopad -k 'key' -d -in sample.tar.gz.aes.1 -out sample.tar.gz")
+ os.system("zcat sample.tar.gz 2>/dev/null > sample.tar")
os.system("tar xf sample.tar")
assert os.path.exists("big")
assert hash == self.md5sum("big")
# extract and check output
for i in xrange(1, 4):
fname = "sample.tar.gz.aes.%d" % i
- os.system("openssl aes-128-cbc -k 'key' -d -in %s -out sample.tar.gz" % fname)
- os.system("zcat sample.tar.gz > sample.tar")
+ os.system("openssl aes-128-cbc -nopad -k 'key' -d -in %s -out sample.tar.gz" % fname)
+ os.system("zcat sample.tar.gz 2>/dev/null > sample.tar")
os.system("tar xf sample.tar")
for key, value in hash.iteritems():