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

B2sum: add -l/--length option #4729

Merged
merged 6 commits into from
Apr 13, 2023
Merged

Conversation

spineki
Copy link
Contributor

@spineki spineki commented Apr 10, 2023

Summary

This pull request adds support for the -l/--length option to b2sum (hashsum).
B2sum supports variable output size if

  • length is a multiple of 8 bits
  • length is less or equal than 512

Related Issue

#4610

Remarks

This is my first attempt to contribute to this project, so I may have missed something. (same goes for naming conventions) !

I added a new function to allow creating a Blake2d instance with custom output size (with_output_bytes). I updated the reset function to use this new function instead of calling ::new().
Eventually, the Blake2d tuple has now a new parameter to keep track of the custom size.

I had to create a new parsing step uu_app_opt_length that behaves more or less like uu_app_opt_bits but cannot share the same code due to different text / names.

Tests

I added a simple test with the --length option enabled. I took example of the sha1 tests in the very same file.

related test: bash util/run-gnu-test.sh tests/misc/b2sum-bsd.sh (-l flags)
Unfortunately, I only have Windows for now and I couldn't run the linux tests.

@uutils uutils deleted a comment from github-actions bot Apr 10, 2023
@cakebaker cakebaker linked an issue Apr 11, 2023 that may be closed by this pull request
@uutils uutils deleted a comment from github-actions bot Apr 11, 2023
@sylvestre
Copy link
Contributor

not your fault but sharing for other reviewers. the test doesn't pass because of:


2023-04-11T08:23:08.2374314Z error: unexpected argument '-c' found
2023-04-11T08:23:08.2374320Z 
2023-04-11T08:23:08.2374477Z   tip: to pass '-c' as a value, use '-- -c'
2023-04-11T08:23:08.2374482Z 
2023-04-11T08:23:08.2374575Z Usage: cksum [OPTIONS] [FILE]...
2023-04-11T08:23:08.2374580Z 
2023-04-11T08:23:08.2374724Z For more information, try '--help'.
2023-04-11T08:23:08.2374833Z FAIL tests/misc/b2sum.sh (exit status: 1)

@cakebaker
Copy link
Contributor

The code looks fine :) Can you please add some tests for the error cases (length too large, length not a multiple of 8), so we don't regress in the future?

@cakebaker cakebaker merged commit dd3c0f7 into uutils:main Apr 13, 2023
@cakebaker
Copy link
Contributor

Thanks, great work :)

@spineki spineki deleted the b2sum-missing-l-option branch April 13, 2023 10:26
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.

b2sum -l X is missing
3 participants