Skip to content

Commit

Permalink
Merge pull request #74 from mattsb42-aws/dev-73
Browse files Browse the repository at this point in the history
Fix stream handler implementation of readable()
  • Loading branch information
mattsb42-aws committed Aug 29, 2018
2 parents d2f1e80 + 7976c3d commit 954ce66
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Changelog
*********

1.3.6 -- 2018-08-29
===================

Bugfixes
--------
* :class:`StreamEncryptor` and :class:`StreamDecryptor` should always report as readable if they are open.
`#73 <https://github.com/aws/aws-encryption-sdk-python/issues/73>`_

1.3.5 -- 2018-08-01
===================
* Move the ``aws-encryption-sdk-python`` repository from ``awslabs`` to ``aws``.
Expand All @@ -18,7 +26,7 @@ Maintenance
-----------
* New minimum pytest version 3.3.1 to avoid bugs in 3.3.0
`#32 <https://github.com/aws/aws-encryption-sdk-python/issues/32>`_
* New minimum attrs version 17.4.0 to allow use of `converter` rather than `convert`
* New minimum attrs version 17.4.0 to allow use of ``converter`` rather than ``convert``
`#39 <https://github.com/aws/aws-encryption-sdk-python/issues/39>`_
* Algorithm Suites are modeled as collections of sub-suites now
`#36 <https://github.com/aws/aws-encryption-sdk-python/pull/36>`_
Expand Down
2 changes: 1 addition & 1 deletion src/aws_encryption_sdk/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from aws_encryption_sdk.exceptions import InvalidAlgorithmError

__version__ = "1.3.5"
__version__ = "1.3.6"
USER_AGENT_SUFFIX = "AwsEncryptionSdkPython/{}".format(__version__)


Expand Down
9 changes: 9 additions & 0 deletions src/aws_encryption_sdk/streaming_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ def __exit__(self, exc_type, exc_value, traceback):
_LOGGER.exception("Error on closing")
return False

def readable(self):
# () -> bool
"""Return `True` if the stream can be read from.
:rtype: bool
"""
# Open streams are currently always readable.
return not self.closed

def read(self, b=None):
"""Returns either the requested number of bytes or the entire stream.
Expand Down
21 changes: 21 additions & 0 deletions test/functional/test_f_aws_encryption_sdk_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,3 +574,24 @@ def test_decrypt_oneshot_no_seek_input():
ciphertext_no_seek = NoSeekBytesIO(ciphertext)
decrypted, _header = aws_encryption_sdk.decrypt(source=ciphertext_no_seek, key_provider=key_provider)
assert decrypted == VALUES["plaintext_128"]


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_decryptor_readable():
"""Verify that open StreamEncryptor instances report as readable."""
key_provider = fake_kms_key_provider()
plaintext = io.BytesIO(VALUES["plaintext_128"])
ciphertext, _header = aws_encryption_sdk.encrypt(source=plaintext, key_provider=key_provider)
with aws_encryption_sdk.StreamDecryptor(source=ciphertext, key_provider=key_provider) as handler:
assert handler.readable()
handler.read()
assert not handler.readable()

0 comments on commit 954ce66

Please sign in to comment.