Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions src/uu/cksum/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ cksum-after-help = DIGEST determines the digest algorithm and default output for
- sha512: (equivalent to sha512sum)
- blake2b: (equivalent to b2sum)
- sm3: (only available through cksum)
- sha3: (requires --length: 224, 256, 384, or 512)
- shake128: (requires --length)
- shake256: (requires --length)

# Help messages
cksum-help-algorithm = select the digest type to use. See DIGEST below
Expand All @@ -29,6 +32,7 @@ cksum-help-status = don't output anything, status code shows success
cksum-help-quiet = don't print OK for each successfully verified file
cksum-help-ignore-missing = don't fail or report status for missing files
cksum-help-zero = end each output line with NUL, not newline, and disable file name escaping
cksum-help-debug = indicate which implementation used

# Error messages
cksum-error-is-directory = { $file }: Is a directory
Expand Down
10 changes: 7 additions & 3 deletions src/uu/cksum/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ cksum-after-help = DIGEST détermine l'algorithme de condensé et le format de s
- sha256 : (équivalent à sha256sum)
- sha384 : (équivalent à sha384sum)
- sha512 : (équivalent à sha512sum)
- blake2b : (équivalent à b2sum)
- sm3 : (disponible uniquement via cksum)
- blake2b: (équivalent à b2sum)
- sm3: (uniquement disponible via cksum)
- sha3: (nécessite --length: 224, 256, 384, ou 512)
- shake128: (nécessite --length)
- shake256: (nécessite --length)

# Messages d'aide
cksum-help-algorithm = sélectionner le type de condensé à utiliser. Voir DIGEST ci-dessous
Expand All @@ -28,7 +31,8 @@ cksum-help-warn = avertir des lignes de somme de contrôle mal formatées
cksum-help-status = ne rien afficher, le code de statut indique le succès
cksum-help-quiet = ne pas afficher OK pour chaque fichier vérifié avec succès
cksum-help-ignore-missing = ne pas échouer ou signaler le statut pour les fichiers manquants
cksum-help-zero = terminer chaque ligne de sortie avec NUL, pas un saut de ligne, et désactiver l'échappement des noms de fichiers
cksum-help-zero = terminer chaque ligne de sortie par NUL, et non par newline, et désactiver l'échappement des noms de fichiers
cksum-help-debug = indiquer quelle implémentation est utilisée

# Messages d'erreur
cksum-error-is-directory = { $file } : Est un répertoire
Expand Down
22 changes: 19 additions & 3 deletions src/uu/cksum/src/cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::path::Path;
use uucore::checksum::{
ALGORITHM_OPTIONS_BLAKE2B, ALGORITHM_OPTIONS_BSD, ALGORITHM_OPTIONS_CRC,
ALGORITHM_OPTIONS_CRC32B, ALGORITHM_OPTIONS_SYSV, ChecksumError, ChecksumOptions,
ChecksumVerbose, SUPPORTED_ALGORITHMS, calculate_blake2b_length, detect_algo, digest_reader,
ChecksumVerbose, SUPPORTED_ALGORITHMS, calculate_blake2b_length, digest_reader,
perform_checksum_validation,
};
use uucore::translate;
Expand Down Expand Up @@ -201,6 +201,7 @@ mod options {
pub const IGNORE_MISSING: &str = "ignore-missing";
pub const QUIET: &str = "quiet";
pub const ZERO: &str = "zero";
pub const DEBUG: &str = "debug";
}

/***
Expand Down Expand Up @@ -256,8 +257,17 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Some(length) => {
if algo_name == ALGORITHM_OPTIONS_BLAKE2B {
calculate_blake2b_length(*length)?
} else if algo_name.starts_with("sha3")
|| algo_name == "shake128"
|| algo_name == "shake256"
{
// SHA3 and SHAKE algorithms require --length in bits
Some(*length)
} else {
return Err(ChecksumError::LengthOnlyForBlake2b.into());
return Err(USimpleError::new(
1,
"--length is only supported with --algorithm=blake2b, sha3, shake128, or shake256",
));
}
}
None => None,
Expand Down Expand Up @@ -308,7 +318,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

let (tag, asterisk) = handle_tag_text_binary_flags(std::env::args_os())?;

let algo = detect_algo(algo_name, length)?;
let algo = uucore::checksum::detect_algo_with_label(algo_name, length, true)?;
let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO));

let output_format = if matches.get_flag(options::RAW) {
Expand Down Expand Up @@ -462,5 +472,11 @@ pub fn uu_app() -> Command {
.help(translate!("cksum-help-zero"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::DEBUG)
.long(options::DEBUG)
.help(translate!("cksum-help-debug"))
.action(ArgAction::SetTrue),
)
.after_help(translate!("cksum-after-help"))
}
31 changes: 27 additions & 4 deletions src/uucore/src/lib/features/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,11 @@ fn print_file_report<W: Write>(
}
}

pub fn detect_algo(algo: &str, length: Option<usize>) -> UResult<HashAlgorithm> {
pub fn detect_algo_with_label(
algo: &str,
length: Option<usize>,
is_cksum: bool,
) -> UResult<HashAlgorithm> {
match algo {
ALGORITHM_OPTIONS_SYSV => Ok(HashAlgorithm {
name: ALGORITHM_OPTIONS_SYSV,
Expand Down Expand Up @@ -437,30 +441,49 @@ pub fn detect_algo(algo: &str, length: Option<usize>) -> UResult<HashAlgorithm>
bits: 512,
}),
ALGORITHM_OPTIONS_SHAKE128 | "shake128sum" => {
let bits = length.ok_or(ChecksumError::BitsRequiredForShake128)?;
let Some(bits) = length else {
if is_cksum {
return Err(USimpleError::new(1, "--length required for SHAKE128"));
}
return Err(ChecksumError::BitsRequiredForShake128.into());
};
Ok(HashAlgorithm {
name: ALGORITHM_OPTIONS_SHAKE128,
create_fn: Box::new(|| Box::new(Shake128::new())),
bits,
})
}
ALGORITHM_OPTIONS_SHAKE256 | "shake256sum" => {
let bits = length.ok_or(ChecksumError::BitsRequiredForShake256)?;
let Some(bits) = length else {
if is_cksum {
return Err(USimpleError::new(1, "--length required for SHAKE256"));
}
return Err(ChecksumError::BitsRequiredForShake256.into());
};
Ok(HashAlgorithm {
name: ALGORITHM_OPTIONS_SHAKE256,
create_fn: Box::new(|| Box::new(Shake256::new())),
bits,
})
}
_ if algo.starts_with("sha3") => {
let bits = length.ok_or(ChecksumError::BitsRequiredForSha3)?;
let Some(bits) = length else {
if is_cksum {
return Err(USimpleError::new(1, "--length required for SHA3"));
}
return Err(ChecksumError::BitsRequiredForSha3.into());
};
create_sha3(bits)
}

_ => Err(ChecksumError::UnknownAlgorithm.into()),
}
}

pub fn detect_algo(algo: &str, length: Option<usize>) -> UResult<HashAlgorithm> {
detect_algo_with_label(algo, length, false)
}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
enum LineFormat {
AlgoBased,
Expand Down
Loading
Loading