Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove Google\CRC32 #6532

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Storage/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
23 changes: 7 additions & 16 deletions Storage/src/Connection/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
vishwarajanand marked this conversation as resolved.
Show resolved Hide resolved
return base64_encode($hash);
}

/**
Expand All @@ -692,13 +684,12 @@ protected function crc32cExtensionLoaded()
/**
* Check if hash() supports crc32c.
*
* Protected access for unit testing.
*
* @deprecated
* @return bool
*/
protected function supportsBuiltinCrc32c()
vishwarajanand marked this conversation as resolved.
Show resolved Hide resolved
{
return Builtin::supports(CRC32::CASTAGNOLI);
return extension_loaded('hash') && in_array('crc32c', hash_algos());
}

/**
Expand Down
6 changes: 2 additions & 4 deletions Storage/tests/System/UploadObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace Google\Cloud\Storage\Tests\System;

use Google\Cloud\Core\Exception\BadRequestException;
use Google\CRC32\CRC32;
use GuzzleHttp\Psr7\Utils;

/**
Expand Down Expand Up @@ -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(),
Expand Down
8 changes: 2 additions & 6 deletions Storage/tests/Unit/Connection/RestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 [
[
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down