← All changes
|
includes/sdk/s3/Aws/Crypto/AesGcmEncryptingStream.php
+9
-9
1.2.8
→
1.4.2
View file →
| @@ -1,14 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Dudlewebs\WPMCS\s3\Aws\Crypto; |
| 4 | 4 | |
| 5 | -use Dudlewebs\WPMCS\s3\Aws\Crypto\Polyfill\AesGcm; | |
| 6 | -use Dudlewebs\WPMCS\s3\Aws\Crypto\Polyfill\Key; | |
| 7 | 5 | use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7; |
| 8 | 6 | use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7\StreamDecoratorTrait; |
| 9 | 7 | use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface; |
| 10 | -use RuntimeException; | |
| 11 | 8 | /** |
| 12 | 9 | * @internal Represents a stream of data to be gcm encrypted. |
| 13 | 10 | */ |
| 14 | 11 | class AesGcmEncryptingStream implements AesStreamInterface, AesStreamInterfaceV2 |
| @@ -21,8 +18,12 @@ | ||
| 21 | 18 | private $plaintext; |
| 22 | 19 | private $tag = ''; |
| 23 | 20 | private $tagLength; |
| 24 | 21 | /** |
| 22 | + * @var StreamInterface | |
| 23 | + */ | |
| 24 | + private $stream; | |
| 25 | + /** | |
| 25 | 26 | * Same as non-static 'getAesName' method, allowing calls in a static |
| 26 | 27 | * context. |
| 27 | 28 | * |
| 28 | 29 | * @return string |
| @@ -46,8 +47,11 @@ | ||
| 46 | 47 | $this->initializationVector = $initializationVector; |
| 47 | 48 | $this->aad = $aad; |
| 48 | 49 | $this->tagLength = $tagLength; |
| 49 | 50 | $this->keySize = $keySize; |
| 51 | + // unsetting the property forces the first access to go through | |
| 52 | + // __get(). | |
| 53 | + unset($this->stream); | |
| 50 | 54 | } |
| 51 | 55 | public function getOpenSslName() |
| 52 | 56 | { |
| 53 | 57 | return "aes-{$this->keySize}-gcm"; |
| @@ -66,13 +70,9 @@ | ||
| 66 | 70 | return $this->initializationVector; |
| 67 | 71 | } |
| 68 | 72 | public function createStream() |
| 69 | 73 | { |
| 70 | - if (\version_compare(\PHP_VERSION, '7.1', '<')) { | |
| 71 | - return Psr7\Utils::streamFor(AesGcm::encrypt((string) $this->plaintext, $this->initializationVector, new Key($this->key), $this->aad, $this->tag, $this->keySize)); | |
| 72 | - } else { | |
| 73 | - return Psr7\Utils::streamFor(\openssl_encrypt((string) $this->plaintext, $this->getOpenSslName(), $this->key, \OPENSSL_RAW_DATA, $this->initializationVector, $this->tag, $this->aad, $this->tagLength)); | |
| 74 | - } | |
| 74 | + return Psr7\Utils::streamFor(\openssl_encrypt((string) $this->plaintext, $this->getOpenSslName(), $this->key, \OPENSSL_RAW_DATA, $this->initializationVector, $this->tag, $this->aad, $this->tagLength)); | |
| 75 | 75 | } |
| 76 | 76 | /** |
| 77 | 77 | * @return string |
| 78 | 78 | */ |
| @@ -79,9 +79,9 @@ | ||
| 79 | 79 | public function getTag() |
| 80 | 80 | { |
| 81 | 81 | return $this->tag; |
| 82 | 82 | } |
| 83 | - public function isWritable() | |
| 83 | + public function isWritable() : bool | |
| 84 | 84 | { |
| 85 | 85 | return \false; |
| 86 | 86 | } |
| 87 | 87 | } |