From 59e4ac30c2ec0d1d3190df93e476db0e21b39da0 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Fri, 13 Jul 2018 01:16:40 -0400 Subject: [PATCH] fixing py2 stuff that broke during py3 fixes --- lbrynet/cryptstream/CryptStreamCreator.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lbrynet/cryptstream/CryptStreamCreator.py b/lbrynet/cryptstream/CryptStreamCreator.py index fe6897327..b41545601 100644 --- a/lbrynet/cryptstream/CryptStreamCreator.py +++ b/lbrynet/cryptstream/CryptStreamCreator.py @@ -102,6 +102,12 @@ class CryptStreamCreator(object): while 1: 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): """Create the symmetric key if it wasn't provided""" @@ -121,7 +127,7 @@ class CryptStreamCreator(object): yield defer.DeferredList(self.finished_deferreds) 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()) stream_terminator = yield final_blob.close() terminator_info = yield self._blob_finished(stream_terminator) @@ -132,7 +138,7 @@ class CryptStreamCreator(object): if self.current_blob is None: self.next_blob_creator = self.blob_manager.get_blob_creator() 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) done, num_bytes_written = self.current_blob.write(data) data = data[num_bytes_written:]