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

checksum: Further rework #6868

Merged
merged 8 commits into from
Nov 26, 2024
Merged

Conversation

RenjiSann
Copy link
Contributor

This PR further rework checksum.rs to get rid of entangled variable processing.

It also partly fixes #6576, for the case where the digest has an odd length (it may still fail in case the length is even but still wrong)

Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@RenjiSann RenjiSann force-pushed the checksum-fix-decoding branch 2 times, most recently from 68cb1c1 to 17769e5 Compare November 21, 2024 10:09
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@RenjiSann RenjiSann force-pushed the checksum-fix-decoding branch 3 times, most recently from 197409f to abd438f Compare November 21, 2024 18:45
@RenjiSann
Copy link
Contributor Author

@sylvestre @cakebaker ping for review ^^

/// from the expectation.
pub failed_cksum: u32,
pub failed_open_file: u32,
/// number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment looks incomplete ;-)

)),
}
BASE64.decode(ck).map(hex::encode).ok()
} else if ck.len() % 2 != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A (pedantic) detail: I would use == for better readability and swap the if and else parts.

Copy link
Contributor

@cakebaker cakebaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two minor details, otherwise it looks good :)

- Rename the function to emphasize its goal
- Do not pass the filename anymore, as it is only used to create an error, that may be done in the scope calling the function
- Change the return type to Option, as the error is made in the outer scope
- Don't try to decode the base64 string as UTF8 string. This most oftenly fails and is wrong.
- Get rid of the `bytes_to_hex` function, as it provides the same functionality as `hex::encode`
- Add comments to explain what each field is counting
@RenjiSann
Copy link
Contributor Author

There are two minor details, otherwise it looks good :)

Thanks for noticing these

@cakebaker cakebaker merged commit cae71a8 into uutils:main Nov 26, 2024
62 checks passed
@cakebaker
Copy link
Contributor

Thanks!

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

Successfully merging this pull request may close these issues.

cksum: incomplete hex checksum is treated as mismatch instead of improper format
2 participants