fixing py2 stuff that broke during py3 fixes

This commit is contained in:
Lex Berezhny 2018-07-13 01:16:40 -04:00 committed by Jack Robison
parent b5ce948bc1
commit 59e4ac30c2
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -102,6 +102,12 @@ class CryptStreamCreator(object):
while 1: while 1:
yield os.urandom(AES.block_size // 8) yield os.urandom(AES.block_size // 8)
def get_next_iv(self):
iv = next(self.iv_generator)
if not isinstance(iv, bytes):
return iv.encode()
return iv
def setup(self): def setup(self):
"""Create the symmetric key if it wasn't provided""" """Create the symmetric key if it wasn't provided"""
@ -121,7 +127,7 @@ class CryptStreamCreator(object):
yield defer.DeferredList(self.finished_deferreds) yield defer.DeferredList(self.finished_deferreds)
self.blob_count += 1 self.blob_count += 1
iv = next(self.iv_generator).encode() iv = self.get_next_iv()
final_blob = self._get_blob_maker(iv, self.blob_manager.get_blob_creator()) final_blob = self._get_blob_maker(iv, self.blob_manager.get_blob_creator())
stream_terminator = yield final_blob.close() stream_terminator = yield final_blob.close()
terminator_info = yield self._blob_finished(stream_terminator) terminator_info = yield self._blob_finished(stream_terminator)
@ -132,7 +138,7 @@ class CryptStreamCreator(object):
if self.current_blob is None: if self.current_blob is None:
self.next_blob_creator = self.blob_manager.get_blob_creator() self.next_blob_creator = self.blob_manager.get_blob_creator()
self.blob_count += 1 self.blob_count += 1
iv = next(self.iv_generator).encode() iv = self.get_next_iv()
self.current_blob = self._get_blob_maker(iv, self.next_blob_creator) self.current_blob = self._get_blob_maker(iv, self.next_blob_creator)
done, num_bytes_written = self.current_blob.write(data) done, num_bytes_written = self.current_blob.write(data)
data = data[num_bytes_written:] data = data[num_bytes_written:]