def test_read_bytes_to_non_framed_body_close(self): test_encryptor = StreamEncryptor( source=self.mock_input_stream, key_provider=self.mock_key_provider ) test_encryptor.signer = MagicMock() test_encryptor._encryption_materials = self.mock_encryption_materials test_encryptor.encryptor = MagicMock() test_encryptor.encryptor.update.return_value = b'123' test_encryptor.encryptor.finalize.return_value = b'456' test_encryptor.encryptor.tag = sentinel.tag self.mock_serialize_non_framed_close.return_value = b'789' self.mock_serialize_footer.return_value = b'0-=' test = test_encryptor._read_bytes_to_non_framed_body(len(self.plaintext) + 1) test_encryptor.signer.update.assert_has_calls( calls=(call(b'123'), call(b'456')), any_order=False ) assert test_encryptor.source_stream.closed test_encryptor.encryptor.finalize.assert_called_once_with() self.mock_serialize_non_framed_close.assert_called_once_with( tag=test_encryptor.encryptor.tag, signer=test_encryptor.signer ) self.mock_serialize_footer.assert_called_once_with(test_encryptor.signer) assert test == b'1234567890-='
def test_read_bytes_to_non_framed_body_close(self): test_encryptor = StreamEncryptor( source=io.BytesIO(self.plaintext), materials_manager=self.mock_materials_manager, commitment_policy=self.mock_commitment_policy, ) test_encryptor.signer = MagicMock() test_encryptor._encryption_materials = self.mock_encryption_materials test_encryptor.encryptor = MagicMock() test_encryptor.encryptor.update.return_value = b"123" test_encryptor.encryptor.finalize.return_value = b"456" test_encryptor.encryptor.tag = sentinel.tag self.mock_serialize_non_framed_close.return_value = b"789" self.mock_serialize_footer.return_value = b"0-=" test = test_encryptor._read_bytes_to_non_framed_body( len(self.plaintext) + 1) test_encryptor.signer.update.assert_has_calls(calls=(call(b"123"), call(b"456")), any_order=False) test_encryptor.encryptor.finalize.assert_called_once_with() self.mock_serialize_non_framed_close.assert_called_once_with( tag=test_encryptor.encryptor.tag, signer=test_encryptor.signer) self.mock_serialize_footer.assert_called_once_with( test_encryptor.signer) assert test == b"1234567890-="
def test_read_bytes_to_non_framed_body(self): pt_stream = io.BytesIO(self.plaintext) test_encryptor = StreamEncryptor( source=pt_stream, key_provider=self.mock_key_provider ) test_encryptor.signer = MagicMock() test_encryptor.encryptor = MagicMock() test_encryptor.encryptor.update.return_value = sentinel.ciphertext test = test_encryptor._read_bytes_to_non_framed_body(5) test_encryptor.encryptor.update.assert_called_once_with(self.plaintext[:5]) test_encryptor.signer.update.assert_called_once_with(sentinel.ciphertext) assert not test_encryptor.source_stream.closed assert test is sentinel.ciphertext
def test_read_bytes_to_non_framed_body_no_signer(self): pt_stream = io.BytesIO(self.plaintext) test_encryptor = StreamEncryptor( source=pt_stream, key_provider=self.mock_key_provider, algorithm=Algorithm.AES_128_GCM_IV12_TAG16 ) test_encryptor._header = MagicMock() test_encryptor.signer = None test_encryptor._encryption_materials = self.mock_encryption_materials test_encryptor.encryptor = MagicMock() test_encryptor.encryptor.update.return_value = b"123" test_encryptor.encryptor.finalize.return_value = b"456" test_encryptor.encryptor.tag = sentinel.tag self.mock_serialize_non_framed_close.return_value = b"789" self.mock_serialize_footer.return_value = b"0-=" test_encryptor._read_bytes_to_non_framed_body(len(self.plaintext) + 1) assert not self.mock_serialize_footer.called
def test_read_bytes_to_non_framed_body(self): pt_stream = io.BytesIO(self.plaintext) test_encryptor = StreamEncryptor( source=pt_stream, materials_manager=self.mock_materials_manager, commitment_policy=self.mock_commitment_policy, ) test_encryptor.signer = MagicMock() test_encryptor.encryptor = MagicMock() test_encryptor._encryption_materials = self.mock_encryption_materials test_encryptor.encryptor.update.return_value = sentinel.ciphertext test_encryptor._StreamEncryptor__unframed_plaintext_cache = pt_stream test = test_encryptor._read_bytes_to_non_framed_body(5) test_encryptor.encryptor.update.assert_called_once_with( self.plaintext[:5]) test_encryptor.signer.update.assert_called_once_with( sentinel.ciphertext) assert test is sentinel.ciphertext