← All changes
|
includes/sdk/s3/Aws/Crypto/AesGcmDecryptingStream.php
+12
-11
1.2.5
→
1.4.2
View file →
| @@ -5,10 +5,8 @@ | ||
| 5 | 5 | use Dudlewebs\WPMCS\s3\Aws\Exception\CryptoException; |
| 6 | 6 | use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7; |
| 7 | 7 | use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7\StreamDecoratorTrait; |
| 8 | 8 | use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface; |
| 9 | -use Dudlewebs\WPMCS\s3\Aws\Crypto\Polyfill\AesGcm; | |
| 10 | -use Dudlewebs\WPMCS\s3\Aws\Crypto\Polyfill\Key; | |
| 11 | 9 | /** |
| 12 | 10 | * @internal Represents a stream of data to be gcm decrypted. |
| 13 | 11 | */ |
| 14 | 12 | class AesGcmDecryptingStream implements AesStreamInterface |
| @@ -21,8 +19,12 @@ | ||
| 21 | 19 | private $cipherText; |
| 22 | 20 | private $tag; |
| 23 | 21 | private $tagLength; |
| 24 | 22 | /** |
| 23 | + * @var StreamInterface | |
| 24 | + */ | |
| 25 | + private $stream; | |
| 26 | + /** | |
| 25 | 27 | * @param StreamInterface $cipherText |
| 26 | 28 | * @param string $key |
| 27 | 29 | * @param string $initializationVector |
| 28 | 30 | * @param string $tag |
| @@ -38,8 +40,11 @@ | ||
| 38 | 40 | $this->tag = $tag; |
| 39 | 41 | $this->aad = $aad; |
| 40 | 42 | $this->tagLength = $tagLength; |
| 41 | 43 | $this->keySize = $keySize; |
| 44 | + // unsetting the property forces the first access to go through | |
| 45 | + // __get(). | |
| 46 | + unset($this->stream); | |
| 42 | 47 | } |
| 43 | 48 | public function getOpenSslName() |
| 44 | 49 | { |
| 45 | 50 | return "aes-{$this->keySize}-gcm"; |
| @@ -53,19 +58,15 @@ | ||
| 53 | 58 | return $this->initializationVector; |
| 54 | 59 | } |
| 55 | 60 | public function createStream() |
| 56 | 61 | { |
| 57 | - if (\version_compare(\PHP_VERSION, '7.1', '<')) { | |
| 58 | - return Psr7\Utils::streamFor(AesGcm::decrypt((string) $this->cipherText, $this->initializationVector, new Key($this->key), $this->aad, $this->tag, $this->keySize)); | |
| 59 | - } else { | |
| 60 | - $result = \openssl_decrypt((string) $this->cipherText, $this->getOpenSslName(), $this->key, \OPENSSL_RAW_DATA, $this->initializationVector, $this->tag, $this->aad); | |
| 61 | - if ($result === \false) { | |
| 62 | - throw new CryptoException('The requested object could not be' . ' decrypted due to an invalid authentication tag.'); | |
| 63 | - } | |
| 64 | - return Psr7\Utils::streamFor($result); | |
| 62 | + $result = \openssl_decrypt((string) $this->cipherText, $this->getOpenSslName(), $this->key, \OPENSSL_RAW_DATA, $this->initializationVector, $this->tag, $this->aad); | |
| 63 | + if ($result === \false) { | |
| 64 | + throw new CryptoException('The requested object could not be ' . 'decrypted due to an invalid authentication tag.'); | |
| 65 | 65 | } |
| 66 | + return Psr7\Utils::streamFor($result); | |
| 66 | 67 | } |
| 67 | - public function isWritable() | |
| 68 | + public function isWritable() : bool | |
| 68 | 69 | { |
| 69 | 70 | return \false; |
| 70 | 71 | } |
| 71 | 72 | } |