diff --git a/Storage/composer.json b/Storage/composer.json index 59f886b6e0fe..b5d14554ae1d 100644 --- a/Storage/composer.json +++ b/Storage/composer.json @@ -6,7 +6,6 @@ "require": { "php": ">=7.4", "google/cloud-core": "^1.51.3", - "google/crc32": "^0.2.0", "ramsey/uuid": "^4.2.3" }, "require-dev": { diff --git a/Storage/src/Connection/Rest.php b/Storage/src/Connection/Rest.php index 4cab69fc6d0a..43b35332fb11 100644 --- a/Storage/src/Connection/Rest.php +++ b/Storage/src/Connection/Rest.php @@ -29,8 +29,6 @@ use Google\Cloud\Core\UriTrait; use Google\Cloud\Storage\Connection\ConnectionInterface; use Google\Cloud\Storage\StorageClient; -use Google\CRC32\Builtin; -use Google\CRC32\CRC32; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MimeType; use GuzzleHttp\Psr7\Request; @@ -660,21 +658,15 @@ private function chooseValidationMethod(array $args) private function crcFromStream(StreamInterface $data) { $pos = $data->tell(); - - if ($pos > 0) { - $data->rewind(); - } - - $crc32c = CRC32::create(CRC32::CASTAGNOLI); - $data->rewind(); + $crc32c = hash_init('crc32c'); while (!$data->eof()) { - $crc32c->update($data->read(1048576)); + $buffer = $data->read(1048576); + hash_update($crc32c, $buffer); } - $data->seek($pos); - - return base64_encode($crc32c->hash(true)); + $hash = hash_final($crc32c, true); + return base64_encode($hash); } /** @@ -692,13 +684,12 @@ protected function crc32cExtensionLoaded() /** * Check if hash() supports crc32c. * - * Protected access for unit testing. - * + * @deprecated * @return bool */ protected function supportsBuiltinCrc32c() { - return Builtin::supports(CRC32::CASTAGNOLI); + return extension_loaded('hash') && in_array('crc32c', hash_algos()); } /** diff --git a/Storage/tests/System/UploadObjectsTest.php b/Storage/tests/System/UploadObjectsTest.php index 4a518672fc02..247724424ce1 100644 --- a/Storage/tests/System/UploadObjectsTest.php +++ b/Storage/tests/System/UploadObjectsTest.php @@ -18,7 +18,6 @@ namespace Google\Cloud\Storage\Tests\System; use Google\Cloud\Core\Exception\BadRequestException; -use Google\CRC32\CRC32; use GuzzleHttp\Psr7\Utils; /** @@ -133,9 +132,8 @@ public function testCrc32cChecksumFails() $path = __DIR__ . '/data/5mb.txt'; - $crc32c = CRC32::create(CRC32::CASTAGNOLI); - $crc32c->update('foobar'); - $badChecksum = base64_encode($crc32c->hash(true)); + $crc32c = hash('crc32c', 'foobar', true); + $badChecksum = base64_encode($crc32c); self::$bucket->upload($path, [ 'name' => uniqid(), diff --git a/Storage/tests/Unit/Connection/RestTest.php b/Storage/tests/Unit/Connection/RestTest.php index af5138e1715b..42942910abf8 100644 --- a/Storage/tests/Unit/Connection/RestTest.php +++ b/Storage/tests/Unit/Connection/RestTest.php @@ -25,9 +25,6 @@ use Google\Cloud\Core\Upload\ResumableUploader; use Google\Cloud\Core\Upload\StreamableUploader; use Google\Cloud\Storage\Connection\Rest; -use Google\Cloud\Storage\Connection\RetryTrait; -use Google\Cloud\Storage\StorageClient; -use Google\CRC32\CRC32; use GuzzleHttp\Promise\Create; use GuzzleHttp\Promise\PromiseInterface; use GuzzleHttp\Psr7\Request; @@ -297,9 +294,8 @@ public function insertObjectProvider() $tempFile->write(str_repeat('0', 5000001)); $logoFile = Utils::streamFor(fopen(__DIR__ . '/../data/logo.svg', 'r')); - $crc32c = CRC32::create(CRC32::CASTAGNOLI); - $crc32c->update((string) $logoFile); - $crcHash = base64_encode($crc32c->hash(true)); + $crc32c = hash('crc32c', (string) $logoFile, true); + $crcHash = base64_encode($crc32c); return [ [ diff --git a/composer.json b/composer.json index dde348b213be..4055d7e88d1b 100644 --- a/composer.json +++ b/composer.json @@ -52,8 +52,7 @@ "ramsey/uuid": "^4.0", "google/gax": "^1.19.1", "google/common-protos": "^4.0", - "google/auth": "^1.18", - "google/crc32": "^0.2.0" + "google/auth": "^1.18" }, "require-dev": { "phpunit/phpunit": "^9.0",