Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5842f14
cksum: simplify nesting
RenjiSann Jul 26, 2024
ccf5559
checksum: Allow for non UTF-8 input
RenjiSann Aug 1, 2024
780db80
test(checksum): add a test for non UTF-8 chars in comments
RenjiSann Aug 2, 2024
f6f0ed9
test(cksum): add multiple tests
RenjiSann Aug 16, 2024
b5bb0a7
feat(checksum): extract algorithm detection in a specific file
RenjiSann Aug 15, 2024
7246067
feat(checksum): move u8/str/OsString conversion to utils
RenjiSann Aug 17, 2024
c00a444
fix(checksum): lines should not be trimmed before regex matching
RenjiSann Aug 31, 2024
4570f1b
feat(checksum): extract line processing into a separate function
RenjiSann Aug 15, 2024
57cd029
feat(checksum): add a ChecksumOption struct to bundle CLI flags
RenjiSann Aug 15, 2024
0e316c2
feat(checksum): extract utility functions to specific file to make lo…
RenjiSann Aug 17, 2024
0aeed93
feat(checksum): introduce a LineCheckError type
RenjiSann Aug 15, 2024
af925e6
feat(checksum): small type/docstring changes
RenjiSann Aug 17, 2024
a0b301c
feat(checksum): refactor get_expected_checksum
RenjiSann Aug 16, 2024
b1d0701
feat(checksum): extract checksum file processing in a separate function
RenjiSann Aug 17, 2024
48531e9
checksum: handle no-length case in algo-based BLAKE2b
RenjiSann Aug 15, 2024
7dce4f2
feat(checksum): get rid of specific Base64 regex
RenjiSann Aug 31, 2024
cf8811d
cksum: Fix handling of both encodings in a single file
RenjiSann Aug 17, 2024
c9fa70f
feat(checksum): prevent incorrectly formatted checksums from stopping…
RenjiSann Aug 28, 2024
5fed16f
feat(checksum): get rid of ChecksumResult at the line level
RenjiSann Aug 30, 2024
f5f6d6c
checksum: handle hexadecimal/base64 confusion and retry
RenjiSann Aug 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions src/uu/cksum/src/cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use std::fs::File;
use std::io::{self, stdin, stdout, BufReader, Read, Write};
use std::iter;
use std::path::Path;
use uucore::checksum::ChecksumOptions;
use uucore::checksum::{
calculate_blake2b_length, detect_algo, digest_reader, perform_checksum_validation,
algo::detect_algo, calculate_blake2b_length, digest_reader, perform_checksum_validation,
ChecksumError, ALGORITHM_OPTIONS_BLAKE2B, ALGORITHM_OPTIONS_BSD, ALGORITHM_OPTIONS_CRC,
ALGORITHM_OPTIONS_SYSV, SUPPORTED_ALGORITHMS,
};
Expand Down Expand Up @@ -262,14 +263,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

let algo_name: &str = match matches.get_one::<String>(options::ALGORITHM) {
Some(v) => v,
None => {
if check {
// if we are doing a --check, we should not default to crc
""
} else {
ALGORITHM_OPTIONS_CRC
}
}
// if we are doing a --check, we should not default to crc
None if check => "",
None => ALGORITHM_OPTIONS_CRC,
};

if ["bsd", "crc", "sysv"].contains(&algo_name) && check {
Expand Down Expand Up @@ -314,17 +310,17 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|| iter::once(OsStr::new("-")).collect::<Vec<_>>(),
|files| files.map(OsStr::new).collect::<Vec<_>>(),
);
return perform_checksum_validation(
files.iter().copied(),
strict,
status,
warn,
binary_flag,

let opts = ChecksumOptions {
binary: binary_flag,
ignore_missing,
quiet,
algo_option,
length,
);
status,
strict,
warn,
};

return perform_checksum_validation(files.iter().copied(), opts, algo_option, length);
}

let (tag, asterisk) = handle_tag_text_binary_flags(&matches)?;
Expand Down
35 changes: 20 additions & 15 deletions src/uu/hashsum/src/hashsum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ use std::io::{stdin, BufReader, Read};
use std::iter;
use std::num::ParseIntError;
use std::path::Path;
use uucore::checksum::calculate_blake2b_length;
use uucore::checksum::create_sha3;
use uucore::checksum::detect_algo;
use uucore::checksum::digest_reader;
use uucore::checksum::escape_filename;
use uucore::checksum::perform_checksum_validation;
use uucore::checksum::ChecksumError;
use uucore::checksum::HashAlgorithm;
use uucore::error::{FromIo, UResult};
use uucore::checksum::ChecksumOptions;
use uucore::checksum::{
algo::{create_sha3, detect_algo},
calculate_blake2b_length, digest_reader, escape_filename, perform_checksum_validation,
ChecksumError,
};
use uucore::sum::{Digest, Sha3_224, Sha3_256, Sha3_384, Sha3_512, Shake128, Shake256};
use uucore::{
checksum::HashAlgorithm,
error::{FromIo, UResult},
};
use uucore::{format_usage, help_about, help_usage};

const NAME: &str = "hashsum";
Expand Down Expand Up @@ -233,15 +234,19 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
|files| files.map(OsStr::new).collect::<Vec<_>>(),
);

let opts = ChecksumOptions {
binary: binary_flag,
ignore_missing,
quiet,
status,
strict,
warn,
};

// Execute the checksum validation
return perform_checksum_validation(
input.iter().copied(),
strict,
status,
warn,
binary_flag,
ignore_missing,
quiet,
opts,
Some(algo.name),
Some(algo.bits),
);
Expand Down
Loading