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

Hash::fromHex #84

Open
dimitre opened this issue Apr 4, 2023 · 8 comments
Open

Hash::fromHex #84

dimitre opened this issue Apr 4, 2023 · 8 comments

Comments

@dimitre
Copy link

dimitre commented Apr 4, 2023

does it exist?

@phlisg
Copy link

phlisg commented Apr 13, 2023

It has been removed in latest commit. I tried reverting to an older commit but things went sideways, so I'm updating my whole db to generate bits hashes instead of hex hashes.

@nghuuquyen
Copy link

I got the same problem for my project. Please help it

@jenssegers
Copy link
Owner

I'll check it out!

@nghuuquyen
Copy link

Yes, thank you so much.
Currently for my project work, I temporary down the version to ^0.8.0 and everything work fine.

@richard-bridgeman
Copy link

Trying to use this project and I need to load a hash from the database to evaluate it. Is this going to be re-implemented any time soon?

@took
Copy link

took commented Aug 28, 2023

@dimitre new Hash(new BigInteger($hex, 16)) should do the trick!

@jenssegers maybe we could refactor the constructor of Hash to accept a string $binaryValue like before, but if the parameter is an array, it may look like this ['fromHex'=>$hex] and the constructor does the new BigInteger($hex, 16) trick (also for "fromBit", and for completeness "fromInt")?

@richard-bridgeman
Copy link

richard-bridgeman commented Aug 28, 2023 via email

@oleg-andreyev
Copy link

oleg-andreyev commented Sep 28, 2023

changing API in minor is a BC-break - not good.


UPD

<?php

namespace App\Helper;

class HashHelper
{
    public static function hashToBits(string $value): string
    {
        $value = hex2bin($value);

        $bits = '';
        $digits = unpack('J*', $value);
        foreach ($digits as $digit) {
            $bits .= sprintf('%064b', $digit);
        }

        return $bits;
    }
}

$hash = '0000000000000000082bfe0000000000';
$h1 = Hash::fromBits(HashHelper::hashToBits($s));
var_dump(str_pad($h1->toHex(), 32, 0, STR_PAD_LEFT) === $s);

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

7 participants