khchen / hashlib

Hash Library for Nim
MIT License
38 stars 4 forks source link

How do you hash a file using hashlib's xxhash? #1

Open firasuke opened 1 year ago

firasuke commented 1 year ago

I am trying to use xxHash3 128 bits for hashing a file, I am using readFile but I am getting an incorrect checksum.

I also tried using streams with openFileStream and I am getting the same wrong checksum.

Any ideas?

firasuke commented 1 year ago

Here is what I am using:

...
import hashlib/misc/xxhash

proc verify*(file: string, checksum: string): bool =
    checksum == $count[XXHASH3_128](readFile(file))
...

Where file is a .tar.gz tarball (I'll be using make-4.4.tar.gz as an example.

I am using xxh128sum to get the expected checksum 15bf27bd70e74eb8c4f71a1028513adf, but the function above is returning a wrong checksum of faae50855f65ad63b1c4c71c19166a3c.

How can I fix this?

firasuke commented 7 months ago

Any updates to this?