GeopJr / Collision

Check hashes for your files - A GUI tool to generate, compare and verify MD5, SHA-1, SHA-256, SHA-512, Blake3, CRC32 & Adler32 hashes.
https://collision.geopjr.dev
BSD 2-Clause "Simplified" License
138 stars 15 forks source link

[Request]: Detect control files and automatically check for correspondence #177

Open Breizhux opened 7 months ago

Breizhux commented 7 months ago

Describe the request

Hello,

Would it be possible to implement a function that automatically detects the checksum file associated with a given file, opens it, extracts the string corresponding to the checksum and automatically compares it to the checksum file?

Let me explain:

Suppose I open a "linux.iso" file to calculate its checksum. Let's imagine that next to it is the file "linux.iso.sha256" or "linux.iso.sha256sum", which is not uncommon, since the two files are often downloaded from the same web page, with the two links next to each other. It would be very useful to automatically detect whether such a file exists next to the open file. Open it, extract the result (often files contain [result sha256]\t[filename, here it would be "linux.iso"] or the reverse order [linux.iso]\t[result sha256].

In short, adding a condition of this style to the opening of a :

input_file = "linux.iso"
control_file = ""
if input_file+".sha256" exists :
    control_file = input_file+".sha256"
if input_file+".sha256sum" exists :
    control_file = input_file+".sha256sum"
if control_file != "" :
    content = read(control_file).split("\t")
    if content[0] == input_file :
        digest = content[1]
    else :
        digest = content[0]
    #when calcul input_file digest, verify if corresponding to readed digest, without others manipulations users.

Thank you for everything you can do!

Implementation Details

GeopJr commented 7 months ago

Thanks for the suggestion!

The main blocker for this is flatpak / portals. Collision can't access the whole folder but only the selected file.

I believe there was a work-in-progress portal to open neighboring files but it's not done yet.

In the meantime, if you select the text file with the hashes in the "Verify" tab, Collision will actually look inside of it and check if any hashes match:

image

(notice that the open file is a .iso while the one in the verify tab is a .sha256)