def test_stream_encryptor_readable(): """Verify that open StreamEncryptor instances report as readable.""" key_provider = fake_kms_key_provider() plaintext = io.BytesIO(VALUES["plaintext_128"]) with aws_encryption_sdk.StreamEncryptor(source=plaintext, key_provider=key_provider) as handler: assert handler.readable() handler.read() assert not handler.readable()
def test_stream_encryptor_readable(): """Verify that open StreamEncryptor instances report as readable.""" key_provider = fake_kms_key_provider() plaintext = io.BytesIO(VALUES["plaintext_128"]) with aws_encryption_sdk.StreamEncryptor( source=plaintext, key_provider=key_provider, commitment_policy=CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT ) as handler: assert handler.readable() handler.read() assert not handler.readable()
def test_stream_encryptor_no_seek_input(): """Test that StreamEncryptor can handle an input stream that is not seekable.""" key_provider = fake_kms_key_provider() plaintext = NoSeekBytesIO(VALUES["plaintext_128"]) ciphertext = io.BytesIO() with aws_encryption_sdk.StreamEncryptor( source=plaintext, key_provider=key_provider, encryption_context=VALUES["encryption_context"] ) as encryptor: for chunk in encryptor: ciphertext.write(chunk) decrypted, _header = aws_encryption_sdk.decrypt(source=ciphertext.getvalue(), key_provider=key_provider) assert decrypted == VALUES["plaintext_128"]
def test_stream_encryptor_no_seek_input(): """Test that StreamEncryptor can handle an input stream that is not seekable.""" key_provider = fake_kms_key_provider() plaintext = NoSeekBytesIO(VALUES["plaintext_128"]) ciphertext = io.BytesIO() with aws_encryption_sdk.StreamEncryptor( source=plaintext, key_provider=key_provider, encryption_context=VALUES["encryption_context"], commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT, ) as encryptor: for chunk in encryptor: ciphertext.write(chunk) decrypted, _header = aws_encryption_sdk.EncryptionSDKClient( commitment_policy=CommitmentPolicy.FORBID_ENCRYPT_ALLOW_DECRYPT ).decrypt(source=ciphertext.getvalue(), key_provider=key_provider) assert decrypted == VALUES["plaintext_128"]