Skip to content

Commit 9ab4afb

Browse files
committed
remove now unnecessary use of source_stream.close()
1 parent 29dbced commit 9ab4afb

File tree

4 files changed

+5
-42
lines changed

4 files changed

+5
-42
lines changed

src/aws_encryption_sdk/streaming_client.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,7 @@ def _read_bytes_to_non_framed_body(self, b):
546546

547547
if len(plaintext) < b:
548548
_LOGGER.debug("Closing encryptor after receiving only %d bytes of %d bytes requested", plaintext_length, b)
549-
self.source_stream.close()
550-
self.__unframed_plaintext_cache.close()
549+
551550
closing = self.encryptor.finalize()
552551

553552
if self.signer is not None:
@@ -625,7 +624,6 @@ def _read_bytes_to_framed_body(self, b):
625624
if self.signer is not None:
626625
output += serialize_footer(self.signer)
627626
self.__message_complete = True
628-
self.source_stream.close()
629627
return output
630628

631629
def _read_bytes(self, b):
@@ -856,7 +854,6 @@ def _read_bytes_from_non_framed_body(self, b):
856854
plaintext += self.decryptor.finalize()
857855

858856
self.footer = deserialize_footer(stream=self.source_stream, verifier=self.verifier)
859-
self.source_stream.close()
860857
return plaintext
861858

862859
def _read_bytes_from_framed_body(self, b):
@@ -898,7 +895,7 @@ def _read_bytes_from_framed_body(self, b):
898895
if final_frame:
899896
_LOGGER.debug("Reading footer")
900897
self.footer = deserialize_footer(stream=self.source_stream, verifier=self.verifier)
901-
self.source_stream.close()
898+
902899
return plaintext
903900

904901
def _read_bytes(self, b):

test/functional/test_f_aws_encryption_sdk_client.py

+3-27
Original file line numberDiff line numberDiff line change
@@ -770,15 +770,7 @@ def close(self):
770770
raise NotImplementedError("NoClose does not close().")
771771

772772

773-
@pytest.mark.parametrize(
774-
"wrapping_class",
775-
(
776-
NoTell,
777-
NoClosed,
778-
pytest.param(NoClose, marks=pytest.mark.xfail(strict=True)),
779-
pytest.param(NothingButRead, marks=pytest.mark.xfail(strict=True)),
780-
),
781-
)
773+
@pytest.mark.parametrize("wrapping_class", (NoTell, NoClosed, NoClose, NothingButRead))
782774
@pytest.mark.parametrize("frame_length", (0, 1024))
783775
def test_cycle_minimal_source_stream_api(frame_length, wrapping_class):
784776
raw_plaintext = exact_length_plaintext(100)
@@ -792,15 +784,7 @@ def test_cycle_minimal_source_stream_api(frame_length, wrapping_class):
792784
assert raw_plaintext == decrypted
793785

794786

795-
@pytest.mark.parametrize(
796-
"wrapping_class",
797-
(
798-
NoTell,
799-
NoClosed,
800-
pytest.param(NoClose, marks=pytest.mark.xfail(strict=True)),
801-
pytest.param(NothingButRead, marks=pytest.mark.xfail(strict=True)),
802-
),
803-
)
787+
@pytest.mark.parametrize("wrapping_class", (NoTell, NoClosed, NoClose, NothingButRead))
804788
@pytest.mark.parametrize("frame_length", (0, 1024))
805789
def test_encrypt_minimal_source_stream_api(frame_length, wrapping_class):
806790
raw_plaintext = exact_length_plaintext(100)
@@ -813,15 +797,7 @@ def test_encrypt_minimal_source_stream_api(frame_length, wrapping_class):
813797
assert raw_plaintext == decrypted
814798

815799

816-
@pytest.mark.parametrize(
817-
"wrapping_class",
818-
(
819-
NoTell,
820-
NoClosed,
821-
pytest.param(NoClose, marks=pytest.mark.xfail(strict=True)),
822-
pytest.param(NothingButRead, marks=pytest.mark.xfail(strict=True)),
823-
),
824-
)
800+
@pytest.mark.parametrize("wrapping_class", (NoTell, NoClosed, NoClose, NothingButRead))
825801
@pytest.mark.parametrize("frame_length", (0, 1024))
826802
def test_decrypt_minimal_source_stream_api(frame_length, wrapping_class):
827803
plaintext = exact_length_plaintext(100)

test/unit/test_streaming_client_stream_decryptor.py

-4
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ def test_read_bytes_from_non_framed(self):
280280
assert test_decryptor.decryptor is self.mock_decryptor_instance
281281
test_decryptor.verifier.update.assert_called_once_with(VALUES["data_128"])
282282
self.mock_decryptor_instance.update.assert_called_once_with(VALUES["data_128"])
283-
assert test_decryptor.source_stream.closed
284283
assert test == b"12345678"
285284

286285
def test_read_bytes_from_non_framed_message_body_too_small(self):
@@ -324,7 +323,6 @@ def test_read_bytes_from_non_framed_finalize(self):
324323
self.mock_deserialize_footer.assert_called_once_with(
325324
stream=test_decryptor.source_stream, verifier=test_decryptor.verifier
326325
)
327-
assert test_decryptor.source_stream.closed
328326
assert test == b"12345678"
329327

330328
def test_read_bytes_from_framed_body_multi_frame_finalize(self):
@@ -459,7 +457,6 @@ def test_read_bytes_from_framed_body_multi_frame_finalize(self):
459457
self.mock_deserialize_footer.assert_called_once_with(
460458
stream=test_decryptor.source_stream, verifier=test_decryptor.verifier
461459
)
462-
assert test_decryptor.source_stream.closed
463460
assert test == b"1234567890-="
464461

465462
def test_read_bytes_from_framed_body_single_frame(self):
@@ -484,7 +481,6 @@ def test_read_bytes_from_framed_body_single_frame(self):
484481
stream=test_decryptor.source_stream, header=test_decryptor._header, verifier=test_decryptor.verifier
485482
)
486483
assert not self.mock_deserialize_footer.called
487-
assert not test_decryptor.source_stream.closed
488484
assert test == b"1234"
489485

490486
def test_read_bytes_from_framed_body_bad_sequence_number(self):

test/unit/test_streaming_client_stream_encryptor.py

-6
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ def test_read_bytes_to_non_framed_body(self):
388388

389389
test_encryptor.encryptor.update.assert_called_once_with(self.plaintext[:5])
390390
test_encryptor.signer.update.assert_called_once_with(sentinel.ciphertext)
391-
assert not test_encryptor.source_stream.closed
392391
assert test is sentinel.ciphertext
393392

394393
def test_read_bytes_to_non_framed_body_too_large(self):
@@ -414,7 +413,6 @@ def test_read_bytes_to_non_framed_body_close(self):
414413
test = test_encryptor._read_bytes_to_non_framed_body(len(self.plaintext) + 1)
415414

416415
test_encryptor.signer.update.assert_has_calls(calls=(call(b"123"), call(b"456")), any_order=False)
417-
assert test_encryptor.source_stream.closed
418416
test_encryptor.encryptor.finalize.assert_called_once_with()
419417
self.mock_serialize_non_framed_close.assert_called_once_with(
420418
tag=test_encryptor.encryptor.tag, signer=test_encryptor.signer
@@ -514,7 +512,6 @@ def test_read_bytes_to_framed_body_single_frame_read(self):
514512
signer=sentinel.signer,
515513
)
516514
assert not self.mock_serialize_footer.called
517-
assert not test_encryptor.source_stream.closed
518515
assert test == b"1234"
519516

520517
def test_read_bytes_to_framed_body_single_frame_with_final(self):
@@ -633,7 +630,6 @@ def test_read_bytes_to_framed_body_multi_frame_read(self):
633630
any_order=False,
634631
)
635632
self.mock_serialize_footer.assert_called_once_with(sentinel.signer)
636-
assert test_encryptor.source_stream.closed
637633
assert test == b"1234567890-=FINAL/*-"
638634

639635
def test_read_bytes_to_framed_body_close(self):
@@ -651,7 +647,6 @@ def test_read_bytes_to_framed_body_close(self):
651647
test_encryptor._read_bytes_to_framed_body(len(self.plaintext) + 1)
652648

653649
self.mock_serialize_footer.assert_called_once_with(sentinel.signer)
654-
assert test_encryptor.source_stream.closed
655650

656651
def test_read_bytes_to_framed_body_close_no_signer(self):
657652
self.mock_serialize_frame.return_value = (b"1234", b"")
@@ -670,7 +665,6 @@ def test_read_bytes_to_framed_body_close_no_signer(self):
670665
test_encryptor._read_bytes_to_framed_body(len(self.plaintext) + 1)
671666

672667
assert not self.mock_serialize_footer.called
673-
assert test_encryptor.source_stream.closed
674668

675669
@patch("aws_encryption_sdk.streaming_client._EncryptionStream.close")
676670
def test_close(self, mock_close):

0 commit comments

Comments
 (0)