diff --git a/src/AesDecryptingStream.php b/src/AesDecryptingStream.php index 66a8258..6341331 100644 --- a/src/AesDecryptingStream.php +++ b/src/AesDecryptingStream.php @@ -46,9 +46,9 @@ public function __construct( $this->cipherMethod = clone $cipherMethod; } - public function eof() + public function eof(): bool { - return $this->cipherBuffer === '' && $this->stream->eof(); + return $this->plainBuffer === '' && $this->cipherBuffer === '' && $this->stream->eof(); } public function getSize(): ?int diff --git a/tests/AesDecryptingStreamTest.php b/tests/AesDecryptingStreamTest.php index 096ca3d..e6a1207 100644 --- a/tests/AesDecryptingStreamTest.php +++ b/tests/AesDecryptingStreamTest.php @@ -198,4 +198,22 @@ public function testEmitsErrorWhenDecryptionFails() $this->assertRegExp("/DecryptionFailedException: Unable to decrypt/", $error); } + + /** + * @dataProvider cipherMethodProvider + * + * @param CipherMethod $iv + */ + public function testDataEndsWithEof( + CipherMethod $iv + ) { + $plain = str_repeat("0", 100); + $cipherStream = new AesEncryptingStream(Psr7\stream_for($plain), self::KEY, clone $iv); + $stream = new AesDecryptingStream($cipherStream, self::KEY, clone $iv); + + while (!$stream->eof()) { + $stream->read(1); + } + $this->assertSame('', $stream->read(1)); + } }