Skip to content

Conversation

sylvestre
Copy link
Contributor

No description provided.

Copy link

GNU testsuite comparison:

GNU test failed: tests/cksum/md5sum. tests/cksum/md5sum is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/cksum/b2sum is no longer failing!
Congrats! The gnu test tests/cksum/cksum-a is no longer failing!

BitsRequiredForShake256,
#[error("--bits required for SHA2")]
BitsRequiredForSha2,
#[error("Invalid output size for SHA2 (expected 224, 256, 384, or 512), got {0}")]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i noticed that we aren't translating this file, i will fix it next

Copy link

GNU testsuite comparison:

GNU test failed: tests/cksum/md5sum. tests/cksum/md5sum is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/cksum/b2sum is no longer failing!
Congrats! The gnu test tests/cksum/cksum-a is no longer failing!

Copy link

codspeed-hq bot commented Sep 28, 2025

CodSpeed Performance Report

Merging #8760 will not alter performance

Comparing sylvestre:cksum (06b8692) with main (52c71dc)

Summary

✅ 41 untouched
⏩ 64 skipped1

Footnotes

  1. 64 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/cksum/b2sum is no longer failing!
Congrats! The gnu test tests/cksum/cksum-a is no longer failing!

@sylvestre sylvestre marked this pull request as ready for review September 29, 2025 07:29
@sylvestre sylvestre requested a review from cakebaker September 29, 2025 07:29
.arg("lorem_ipsum.txt")
.fails_with_code(1)
.no_stdout()
.stderr_contains("--bits required for SHA2");
Copy link
Contributor

Choose a reason for hiding this comment

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

The expected error message is incorrect as there is no --bits option.

Suggested change
.stderr_contains("--bits required for SHA2");
.stderr_contains("--length required for SHA2");

GNU cksum itself shows the following error:

cksum: --algorithm=sha2 requires specifying --length 224, 256, 384, or 512

}

#[test]
fn test_sha2_with_length_224() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It might make sense to combine the test_sha2_with_length_xxx tests into a single test function that loops over the valid lengths.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we could leverage rstest here. It offers parametrized tests (the macro generates all the testcases independently). See https://github.com/la10736/rstest?tab=readme-ov-file#parametrize

Comment on lines +2492 to +2495
// Should contain base64 characters and SHA256 label
assert!(result.contains("SHA256"));
// Base64 should end with = or == or contain +/
assert!(result.contains('=') || result.contains('+') || result.contains('/'));
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use a single assert and check for the correct output. The second assert is currently true independent of whether the output is base64 because result.contains('=') matches the delimiter between hash name and hash. And the "or" conditions are not necessary because you know the expected output.

#[error("--bits required for SHA2")]
BitsRequiredForSha2,
#[error("Invalid output size for SHA2 (expected 224, 256, 384, or 512), got {0}")]
InvalidSha2Length(usize),
Copy link
Contributor

Choose a reason for hiding this comment

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

For SHA3 we use InvalidOutputSizeForSha3, and so for consistency reasons I would use a similar name:

Suggested change
InvalidSha2Length(usize),
InvalidOutputSizeForSha2(usize),

Comment on lines +1313 to +1323
let error_key = format!("{}-error-invalid-length", utility_name);
let max_key = format!("{}-error-max-digest-length", utility_name);
show_error!(
"{}",
translate!(&error_key, "length" => DisplayQuotable::quote(length_str))
);
Err(io::Error::new(
io::ErrorKind::InvalidInput,
translate!(&max_key, "algorithm" => "BLAKE2b", "max_bits" => 512),
)
.into())
Copy link
Collaborator

Choose a reason for hiding this comment

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

This part is almost a duplicate of the ones above, there might be a way to factorize it with closures ?


/// Validate BLAKE2b length with Fluent error messages
/// This function is used by utilities that need localized error messages
pub fn validate_blake2b_length(length_str: &str, utility_name: &str) -> UResult<Option<usize>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm struggling with this function as it duplicates the code of validate_blake2b_length_str and calculate_blake2b_length. And thus it makes it easy to introduce sync issues in the future.

pub const ALGORITHM_OPTIONS_SM3: &str = "sm3";
pub const ALGORITHM_OPTIONS_SHAKE128: &str = "shake128";
pub const ALGORITHM_OPTIONS_SHAKE256: &str = "shake256";
pub const ALGORITHM_OPTIONS_SHA2: &str = "sha2";
Copy link
Contributor

Choose a reason for hiding this comment

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

A detail: I would move this line up to line 39, so that it is between the consts for SHA1 and SHA3.

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.

Done :)

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.

3 participants