diff --git a/Cargo.lock b/Cargo.lock index 9db65e310..17c05da50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -631,6 +631,7 @@ dependencies = [ "uu_sha224sum", "uu_sha256sum", "uu_sha384sum", + "uu_sha512sum", "uu_shred", "uu_shuf", "uu_sleep", @@ -4036,6 +4037,18 @@ dependencies = [ "uucore", ] +[[package]] +name = "uu_sha512sum" +version = "0.6.0" +dependencies = [ + "clap", + "codspeed-divan-compat", + "fluent", + "tempfile", + "uu_checksum_common", + "uucore", +] + [[package]] name = "uu_shred" version = "0.6.0" diff --git a/Cargo.toml b/Cargo.toml index a24e87060..12e062f8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -92,6 +92,7 @@ feat_common_core = [ "sha224sum", "sha256sum", "sha384sum", + "sha512sum", "comm", "cp", "csplit", @@ -449,6 +450,7 @@ sha1sum = { optional = true, version = "0.6.0", package = "uu_sha1sum", path = " sha224sum = { optional = true, version = "0.6.0", package = "uu_sha224sum", path = "src/uu/sha224sum" } sha256sum = { optional = true, version = "0.6.0", package = "uu_sha256sum", path = "src/uu/sha256sum" } sha384sum = { optional = true, version = "0.6.0", package = "uu_sha384sum", path = "src/uu/sha384sum" } +sha512sum = { optional = true, version = "0.6.0", package = "uu_sha512sum", path = "src/uu/sha512sum" } comm = { optional = true, version = "0.6.0", package = "uu_comm", path = "src/uu/comm" } cp = { optional = true, version = "0.6.0", package = "uu_cp", path = "src/uu/cp" } csplit = { optional = true, version = "0.6.0", package = "uu_csplit", path = "src/uu/csplit" } diff --git a/GNUmakefile b/GNUmakefile index 7805ff9d6..b1c8ff2dc 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -95,9 +95,6 @@ SELINUX_PROGS := \ chcon \ runcon -HASHSUM_PROGS := \ - sha512sum - $(info Detected OS = $(OS)) ifeq (,$(findstring MINGW,$(OS))) diff --git a/build.rs b/build.rs index 8a5e0ec5c..a7eb90312 100644 --- a/build.rs +++ b/build.rs @@ -89,9 +89,6 @@ pub fn main() { } "hashsum" => { phf_map.entry(krate, format!("({krate}::uumain, {krate}::uu_app_custom)")); - - let map_value = format!("({krate}::uumain, {krate}::uu_app_common)"); - phf_map.entry("sha512sum", map_value.clone()); } _ => { phf_map.entry(krate, map_value.clone()); diff --git a/src/common/validation.rs b/src/common/validation.rs index 5c90de222..d723ca926 100644 --- a/src/common/validation.rs +++ b/src/common/validation.rs @@ -50,9 +50,6 @@ fn get_canonical_util_name(util_name: &str) -> &str { // uu_test aliases - '[' is an alias for test "[" => "test", - // hashsum aliases - all these hash commands are aliases for hashsum - "sha512sum" => "hashsum", - "dir" => "ls", // dir is an alias for ls // Default case - return the util name as is diff --git a/src/uu/sha512sum/Cargo.toml b/src/uu/sha512sum/Cargo.toml new file mode 100644 index 000000000..0cea1453b --- /dev/null +++ b/src/uu/sha512sum/Cargo.toml @@ -0,0 +1,38 @@ +[package] +name = "uu_sha512sum" +description = "sha512sum ~ (uutils) Print or check the SHA512 checksums" +repository = "https://github.com/uutils/coreutils/tree/main/src/uu/sha512sum" +version.workspace = true +authors.workspace = true +license.workspace = true +homepage.workspace = true +keywords.workspace = true +categories.workspace = true +edition.workspace = true +readme.workspace = true + +[lints] +workspace = true + +[lib] +path = "src/sha512sum.rs" + +[dependencies] +clap = { workspace = true } +uu_checksum_common = { workspace = true } +uucore = { workspace = true, features = [ + "checksum", + "encoding", + "sum", + "hardware", +] } +fluent = { workspace = true } + +[dev-dependencies] +divan = { workspace = true } +tempfile = { workspace = true } +uucore = { workspace = true, features = ["benchmark"] } + +[[bin]] +name = "sha512sum" +path = "src/main.rs" diff --git a/src/uu/sha512sum/LICENSE b/src/uu/sha512sum/LICENSE new file mode 120000 index 000000000..5853aaea5 --- /dev/null +++ b/src/uu/sha512sum/LICENSE @@ -0,0 +1 @@ +../../../LICENSE \ No newline at end of file diff --git a/src/uu/sha512sum/locales/en-US.ftl b/src/uu/sha512sum/locales/en-US.ftl new file mode 100644 index 000000000..395a90077 --- /dev/null +++ b/src/uu/sha512sum/locales/en-US.ftl @@ -0,0 +1,2 @@ +sha512sum-about = Print or check the SHA512 checksums +sha512sum-usage = sha512sum [OPTIONS] [FILE]... diff --git a/src/uu/sha512sum/locales/fr-FR.ftl b/src/uu/sha512sum/locales/fr-FR.ftl new file mode 100644 index 000000000..59abcc2f9 --- /dev/null +++ b/src/uu/sha512sum/locales/fr-FR.ftl @@ -0,0 +1,2 @@ +sha512sum-about = Afficher le SHA512 et la taille de chaque fichier +sha512sum-usage = sha512sum [OPTION]... [FICHIER]... diff --git a/src/uu/sha512sum/src/main.rs b/src/uu/sha512sum/src/main.rs new file mode 100644 index 000000000..64a6ecea6 --- /dev/null +++ b/src/uu/sha512sum/src/main.rs @@ -0,0 +1 @@ +uucore::bin!(uu_sha512sum); diff --git a/src/uu/sha512sum/src/sha512sum.rs b/src/uu/sha512sum/src/sha512sum.rs new file mode 100644 index 000000000..125d263f0 --- /dev/null +++ b/src/uu/sha512sum/src/sha512sum.rs @@ -0,0 +1 @@ +uu_checksum_common::declare_standalone!("sha512sum", uucore::checksum::AlgoKind::Sha512); diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 75b00426b..228ca3ede 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -172,9 +172,6 @@ pub fn get_canonical_util_name(util_name: &str) -> &str { // uu_test aliases - '[' is an alias for test "[" => "test", - // hashsum aliases - all these hash commands are aliases for hashsum - "sha512sum" => "hashsum", - "dir" => "ls", // dir is an alias for ls // Default case - return the util name as is diff --git a/src/uucore/src/lib/mods/locale.rs b/src/uucore/src/lib/mods/locale.rs index a2994b6e3..a6dad4c62 100644 --- a/src/uucore/src/lib/mods/locale.rs +++ b/src/uucore/src/lib/mods/locale.rs @@ -165,6 +165,7 @@ fn create_bundle( "sha224sum", "sha256sum", "sha384sum", + "sha512sum", ] .contains(&util_name) { diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index 0e23ecd59..c139469d6 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -205,7 +205,6 @@ test_digest! {b3sum, b3sum} test_digest! {shake128, shake128} test_digest! {shake256, shake256} -test_digest_with_len! {sha512, sha512, 512} test_digest_with_len! {sha3_224, sha3, 224} test_digest_with_len! {sha3_256, sha3, 256} test_digest_with_len! {sha3_384, sha3, 384} diff --git a/tests/by-util/test_sha512sum.rs b/tests/by-util/test_sha512sum.rs new file mode 100644 index 000000000..5e01ad32a --- /dev/null +++ b/tests/by-util/test_sha512sum.rs @@ -0,0 +1,122 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +use uutests::new_ucmd; +// spell-checker:ignore checkfile, testf, ntestf +macro_rules! get_hash( + ($str:expr) => ( + $str.split(' ').collect::>()[0] + ); +); + +macro_rules! test_digest { + ($id:ident) => { + mod $id { + use uutests::util::*; + use uutests::util_name; + static EXPECTED_FILE: &'static str = concat!(stringify!($id), ".expected"); + static CHECK_FILE: &'static str = concat!(stringify!($id), ".checkfile"); + static INPUT_FILE: &'static str = "input.txt"; + + #[test] + fn test_single_file() { + let ts = TestScenario::new(util_name!()); + assert_eq!( + ts.fixtures.read(EXPECTED_FILE), + get_hash!( + ts.ucmd() + .arg(INPUT_FILE) + .succeeds() + .no_stderr() + .stdout_str() + ) + ); + } + + #[test] + fn test_stdin() { + let ts = TestScenario::new(util_name!()); + assert_eq!( + ts.fixtures.read(EXPECTED_FILE), + get_hash!( + ts.ucmd() + .pipe_in_fixture(INPUT_FILE) + .succeeds() + .no_stderr() + .stdout_str() + ) + ); + } + + #[test] + fn test_check() { + let ts = TestScenario::new(util_name!()); + println!("File content='{}'", ts.fixtures.read(INPUT_FILE)); + println!("Check file='{}'", ts.fixtures.read(CHECK_FILE)); + + ts.ucmd() + .args(&["--check", CHECK_FILE]) + .succeeds() + .no_stderr() + .stdout_is("input.txt: OK\n"); + } + + #[test] + fn test_zero() { + let ts = TestScenario::new(util_name!()); + assert_eq!( + ts.fixtures.read(EXPECTED_FILE), + get_hash!( + ts.ucmd() + .arg("--zero") + .arg(INPUT_FILE) + .succeeds() + .no_stderr() + .stdout_str() + ) + ); + } + + #[test] + fn test_missing_file() { + let ts = TestScenario::new(util_name!()); + let at = &ts.fixtures; + + at.write("a", "file1\n"); + at.write("c", "file3\n"); + + ts.ucmd() + .args(&["a", "b", "c"]) + .fails() + .stdout_contains("a\n") + .stdout_contains("c\n") + .stderr_contains("b: No such file or directory"); + } + } + }; +} + +test_digest! {sha512} + +#[test] +fn test_invalid_arg() { + new_ucmd!().arg("--definitely-invalid").fails_with_code(1); +} + +#[test] +fn test_conflicting_arg() { + new_ucmd!().arg("--tag").arg("--check").fails_with_code(1); + new_ucmd!().arg("--tag").arg("--text").fails_with_code(1); +} + +#[test] +fn test_help_shows_correct_utility_name() { + // Test that help output shows the actual utility name instead of "hashsum" + new_ucmd!() + .arg("--help") + .succeeds() + .stdout_contains("Usage: sha512sum") + .stdout_does_not_contain("Usage: hashsum"); +} diff --git a/tests/fixtures/sha512sum/input.txt b/tests/fixtures/sha512sum/input.txt new file mode 100644 index 000000000..8c01d89ae --- /dev/null +++ b/tests/fixtures/sha512sum/input.txt @@ -0,0 +1 @@ +hello, world \ No newline at end of file diff --git a/tests/fixtures/sha512sum/sha512.checkfile b/tests/fixtures/sha512sum/sha512.checkfile new file mode 100644 index 000000000..41a55cabb --- /dev/null +++ b/tests/fixtures/sha512sum/sha512.checkfile @@ -0,0 +1 @@ +8710339dcb6814d0d9d2290ef422285c9322b7163951f9a0ca8f883d3305286f44139aa374848e4174f5aada663027e4548637b6d19894aec4fb6c46a139fbf9 input.txt diff --git a/tests/fixtures/sha512sum/sha512.expected b/tests/fixtures/sha512sum/sha512.expected new file mode 100644 index 000000000..fd8173686 --- /dev/null +++ b/tests/fixtures/sha512sum/sha512.expected @@ -0,0 +1 @@ +8710339dcb6814d0d9d2290ef422285c9322b7163951f9a0ca8f883d3305286f44139aa374848e4174f5aada663027e4548637b6d19894aec4fb6c46a139fbf9 \ No newline at end of file diff --git a/tests/tests.rs b/tests/tests.rs index 0cc604994..d2ecbca10 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -92,6 +92,10 @@ mod test_sha256sum; #[path = "by-util/test_sha384sum.rs"] mod test_sha384sum; +#[cfg(feature = "sha512sum")] +#[path = "by-util/test_sha512sum.rs"] +mod test_sha512sum; + #[cfg(feature = "cp")] #[path = "by-util/test_cp.rs"] mod test_cp;