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

Different outputs for different implementations #4

Closed
jdpedrie opened this issue Apr 23, 2019 · 0 comments
Closed

Different outputs for different implementations #4

jdpedrie opened this issue Apr 23, 2019 · 0 comments

Comments

@jdpedrie
Copy link
Contributor

jdpedrie commented Apr 23, 2019

When $raw_output is set to true, hash() outputs vary between implementations.

$input = random_bytes(10000);

$crcG = new Google(CRC32::CASTAGNOLI);
$crcG->update($input);

$crcP = new PHP(CRC32::CASTAGNOLI);
$crcP->update($input);

var_dump($crcG->hash(true) === $crcP->hash(true)); // false

I tested all four implementations against an upload to Cloud Storage against PHP 7.2 and PHP 7.3.

Case: Google\CRC32\Builtin
SUCCESS

Case: Google\CRC32\Google
SUCCESS

Case: Google\CRC32\PHP
FAIL

Case: Google\CRC32\PHPSlicedBy4
FAIL
use Google\CRC32\Builtin;
use Google\CRC32\CRC32;
use Google\CRC32\Google;
use Google\CRC32\PHP;
use Google\CRC32\PHPSlicedBy4;

$content = random_bytes(1000);

$classes = [
    Builtin::class,
    Google::class,
    PHP::class,
    PHPSlicedBy4::class
];

foreach ($classes as $class) {
    $crc = new $class(CRC32::CASTAGNOLI);
    $crc->update($content);
    print('Case: ' . $class . PHP_EOL);
    try {
        $bucket->upload($content, [
            'name' => uniqid(),
            'metadata' => [
                'crc32c' => base64_encode($crc->hash(true))
            ]
        ]);
        print('SUCCESS' . PHP_EOL);
    } catch (\Exception $e) {
        print('FAIL' . PHP_EOL);
    }
    print('' . PHP_EOL);
}
@bramp bramp closed this as completed in 3edf450 Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant