mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
sha256sum: introduce standalone binary
This commit is contained in:
Generated
+13
@@ -629,6 +629,7 @@ dependencies = [
|
||||
"uu_seq",
|
||||
"uu_sha1sum",
|
||||
"uu_sha224sum",
|
||||
"uu_sha256sum",
|
||||
"uu_shred",
|
||||
"uu_shuf",
|
||||
"uu_sleep",
|
||||
@@ -4010,6 +4011,18 @@ dependencies = [
|
||||
"uucore",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uu_sha256sum"
|
||||
version = "0.6.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"codspeed-divan-compat",
|
||||
"fluent",
|
||||
"tempfile",
|
||||
"uu_checksum_common",
|
||||
"uucore",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uu_shred"
|
||||
version = "0.6.0"
|
||||
|
||||
@@ -90,6 +90,7 @@ feat_common_core = [
|
||||
"md5sum",
|
||||
"sha1sum",
|
||||
"sha224sum",
|
||||
"sha256sum",
|
||||
"comm",
|
||||
"cp",
|
||||
"csplit",
|
||||
@@ -445,6 +446,7 @@ b2sum = { optional = true, version = "0.6.0", package = "uu_b2sum", path = "src/
|
||||
md5sum = { optional = true, version = "0.6.0", package = "uu_md5sum", path = "src/uu/md5sum" }
|
||||
sha1sum = { optional = true, version = "0.6.0", package = "uu_sha1sum", path = "src/uu/sha1sum" }
|
||||
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" }
|
||||
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" }
|
||||
|
||||
@@ -96,7 +96,6 @@ SELINUX_PROGS := \
|
||||
runcon
|
||||
|
||||
HASHSUM_PROGS := \
|
||||
sha256sum \
|
||||
sha384sum \
|
||||
sha512sum
|
||||
|
||||
|
||||
@@ -91,7 +91,6 @@ pub fn main() {
|
||||
phf_map.entry(krate, format!("({krate}::uumain, {krate}::uu_app_custom)"));
|
||||
|
||||
let map_value = format!("({krate}::uumain, {krate}::uu_app_common)");
|
||||
phf_map.entry("sha256sum", map_value.clone());
|
||||
phf_map.entry("sha384sum", map_value.clone());
|
||||
phf_map.entry("sha512sum", map_value.clone());
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ fn get_canonical_util_name(util_name: &str) -> &str {
|
||||
"[" => "test",
|
||||
|
||||
// hashsum aliases - all these hash commands are aliases for hashsum
|
||||
"sha256sum" | "sha384sum" | "sha512sum" => "hashsum",
|
||||
"sha384sum" | "sha512sum" => "hashsum",
|
||||
|
||||
"dir" => "ls", // dir is an alias for ls
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
[package]
|
||||
name = "uu_sha256sum"
|
||||
description = "sha256sum ~ (uutils) Print or check the SHA256 checksums"
|
||||
repository = "https://github.com/uutils/coreutils/tree/main/src/uu/sha256sum"
|
||||
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/sha256sum.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 = "sha256sum"
|
||||
path = "src/main.rs"
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../../LICENSE
|
||||
@@ -0,0 +1,2 @@
|
||||
sha256sum-about = Print or check the SHA256 checksums
|
||||
sha256sum-usage = sha256sum [OPTIONS] [FILE]...
|
||||
@@ -0,0 +1,2 @@
|
||||
sha256sum-about = Afficher le SHA256 et la taille de chaque fichier
|
||||
sha256sum-usage = sha256sum [OPTION]... [FICHIER]...
|
||||
@@ -0,0 +1 @@
|
||||
uucore::bin!(uu_sha256sum);
|
||||
@@ -0,0 +1 @@
|
||||
uu_checksum_common::declare_standalone!("sha256sum", uucore::checksum::AlgoKind::Sha256);
|
||||
@@ -173,7 +173,7 @@ pub fn get_canonical_util_name(util_name: &str) -> &str {
|
||||
"[" => "test",
|
||||
|
||||
// hashsum aliases - all these hash commands are aliases for hashsum
|
||||
"sha256sum" | "sha384sum" | "sha512sum" => "hashsum",
|
||||
"sha384sum" | "sha512sum" => "hashsum",
|
||||
|
||||
"dir" => "ls", // dir is an alias for ls
|
||||
|
||||
|
||||
@@ -157,7 +157,16 @@ fn create_bundle(
|
||||
try_add_resource_from(get_locales_dir(util_name).ok());
|
||||
|
||||
// checksum binaries also require fluent files from the checksum_common crate
|
||||
if ["cksum", "b2sum", "md5sum", "sha1sum", "sha224sum"].contains(&util_name) {
|
||||
if [
|
||||
"cksum",
|
||||
"b2sum",
|
||||
"md5sum",
|
||||
"sha1sum",
|
||||
"sha224sum",
|
||||
"sha256sum",
|
||||
]
|
||||
.contains(&util_name)
|
||||
{
|
||||
try_add_resource_from(get_locales_dir("checksum_common").ok());
|
||||
}
|
||||
|
||||
|
||||
@@ -205,7 +205,6 @@ test_digest! {b3sum, b3sum}
|
||||
test_digest! {shake128, shake128}
|
||||
test_digest! {shake256, shake256}
|
||||
|
||||
test_digest_with_len! {sha256, sha256, 256}
|
||||
test_digest_with_len! {sha384, sha384, 384}
|
||||
test_digest_with_len! {sha512, sha512, 512}
|
||||
test_digest_with_len! {sha3_224, sha3, 224}
|
||||
@@ -618,6 +617,7 @@ fn test_conflicting_arg() {
|
||||
.fails_with_code(1);
|
||||
}
|
||||
|
||||
#[ignore = "moved to standalone"]
|
||||
#[test]
|
||||
fn test_tag() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
@@ -1184,6 +1184,7 @@ fn test_check_md5_comment_leading_space() {
|
||||
.stderr_contains("WARNING: 1 line is improperly formatted");
|
||||
}
|
||||
|
||||
#[ignore = "moved to standalone"]
|
||||
#[test]
|
||||
fn test_sha256_binary() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
@@ -1200,6 +1201,7 @@ fn test_sha256_binary() {
|
||||
);
|
||||
}
|
||||
|
||||
#[ignore = "moved to standalone"]
|
||||
#[test]
|
||||
fn test_sha256_stdin_binary() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
@@ -1217,8 +1219,8 @@ fn test_sha256_stdin_binary() {
|
||||
}
|
||||
|
||||
// This test is currently disabled on windows
|
||||
#[ignore = "moved to standalone"]
|
||||
#[test]
|
||||
#[cfg_attr(windows, ignore = "Discussion is in #9168")]
|
||||
fn test_check_sha256_binary() {
|
||||
new_ucmd!()
|
||||
.args(&["--sha256", "--check", "binary.sha256.checkfile"])
|
||||
@@ -1241,12 +1243,12 @@ fn test_help_shows_correct_utility_name() {
|
||||
// .stdout_does_not_contain("Usage: hashsum");
|
||||
|
||||
// Test sha256sum
|
||||
scene
|
||||
.ccmd("sha256sum")
|
||||
.arg("--help")
|
||||
.succeeds()
|
||||
.stdout_contains("Usage: sha256sum")
|
||||
.stdout_does_not_contain("Usage: hashsum");
|
||||
// scene
|
||||
// .ccmd("sha256sum")
|
||||
// .arg("--help")
|
||||
// .succeeds()
|
||||
// .stdout_contains("Usage: sha256sum")
|
||||
// .stdout_does_not_contain("Usage: hashsum");
|
||||
|
||||
// Test b2sum
|
||||
// scene
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
// 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;
|
||||
use uutests::util::TestScenario;
|
||||
use uutests::util_name;
|
||||
// spell-checker:ignore checkfile, testf, ntestf
|
||||
macro_rules! get_hash(
|
||||
($str:expr) => (
|
||||
$str.split(' ').collect::<Vec<&str>>()[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! {sha256}
|
||||
|
||||
#[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_tag() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.write("foobar", "foo bar\n");
|
||||
scene
|
||||
.ccmd("sha256sum")
|
||||
.arg("--tag")
|
||||
.arg("foobar")
|
||||
.succeeds()
|
||||
.stdout_is(
|
||||
"SHA256 (foobar) = 1f2ec52b774368781bed1d1fb140a92e0eb6348090619c9291f9a5a3c8e8d151\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sha256_binary() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
assert_eq!(
|
||||
ts.fixtures.read("binary.sha256.expected"),
|
||||
get_hash!(
|
||||
ts.ucmd()
|
||||
.arg("binary.png")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_str()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sha256_stdin_binary() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
assert_eq!(
|
||||
ts.fixtures.read("binary.sha256.expected"),
|
||||
get_hash!(
|
||||
ts.ucmd()
|
||||
.pipe_in_fixture("binary.png")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_str()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// This test is currently disabled on windows
|
||||
#[test]
|
||||
#[cfg_attr(windows, ignore = "Discussion is in #9168")]
|
||||
fn test_check_sha256_binary() {
|
||||
new_ucmd!()
|
||||
.args(&["--check", "binary.sha256.checkfile"])
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_is("binary.png: OK\n");
|
||||
}
|
||||
|
||||
#[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: sha256sum")
|
||||
.stdout_does_not_contain("Usage: hashsum");
|
||||
}
|
||||
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 7.9 KiB |
Vendored
Vendored
Vendored
+1
@@ -0,0 +1 @@
|
||||
hello, world
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user