Add sha284sum
and sha512sum
applets
This commit is contained in:
parent
5e0c1141ef
commit
5fd1bb1220
@ -52,8 +52,13 @@ code between applets, making for an overall smaller binary.
|
|||||||
- rev
|
- rev
|
||||||
- rm
|
- rm
|
||||||
- rmdir
|
- rmdir
|
||||||
- sleep
|
- sha1sum
|
||||||
|
- sha224sum
|
||||||
|
- sha256sum
|
||||||
|
- sha384sum
|
||||||
|
- sha512sum
|
||||||
- shitbox
|
- shitbox
|
||||||
|
- sleep
|
||||||
- sync
|
- sync
|
||||||
- true
|
- true
|
||||||
- unlink
|
- unlink
|
||||||
|
@ -47,6 +47,8 @@ mod rmdir;
|
|||||||
mod sha1sum;
|
mod sha1sum;
|
||||||
mod sha224sum;
|
mod sha224sum;
|
||||||
mod sha256sum;
|
mod sha256sum;
|
||||||
|
mod sha384sum;
|
||||||
|
mod sha512sum;
|
||||||
mod shitbox;
|
mod shitbox;
|
||||||
mod sleep;
|
mod sleep;
|
||||||
mod sync;
|
mod sync;
|
||||||
@ -114,6 +116,8 @@ pub fn get(name: &str) -> Option<Box<dyn Cmd>> {
|
|||||||
"sha1sum" => Some(Box::new(sha1sum::Sha1sum::default())),
|
"sha1sum" => Some(Box::new(sha1sum::Sha1sum::default())),
|
||||||
"sha224sum" => Some(Box::new(sha224sum::Sha224sum::default())),
|
"sha224sum" => Some(Box::new(sha224sum::Sha224sum::default())),
|
||||||
"sha256sum" => Some(Box::new(sha256sum::Sha256sum::default())),
|
"sha256sum" => Some(Box::new(sha256sum::Sha256sum::default())),
|
||||||
|
"sha384sum" => Some(Box::new(sha384sum::Sha384sum::default())),
|
||||||
|
"sha512sum" => Some(Box::new(sha512sum::Sha512sum::default())),
|
||||||
"shitbox" => Some(Box::new(shitbox::Shitbox::default())),
|
"shitbox" => Some(Box::new(shitbox::Shitbox::default())),
|
||||||
"sleep" => Some(Box::new(sleep::Sleep::default())),
|
"sleep" => Some(Box::new(sleep::Sleep::default())),
|
||||||
"sync" => Some(Box::new(sync::Sync::default())),
|
"sync" => Some(Box::new(sync::Sync::default())),
|
||||||
@ -127,7 +131,7 @@ pub fn get(name: &str) -> Option<Box<dyn Cmd>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static COMMANDS: [&str; 47] = [
|
pub static COMMANDS: [&str; 49] = [
|
||||||
"base32",
|
"base32",
|
||||||
"base64",
|
"base64",
|
||||||
"basename",
|
"basename",
|
||||||
@ -166,6 +170,8 @@ pub static COMMANDS: [&str; 47] = [
|
|||||||
"sha1sum",
|
"sha1sum",
|
||||||
"sha224sum",
|
"sha224sum",
|
||||||
"sha256sum",
|
"sha256sum",
|
||||||
|
"sha384sum",
|
||||||
|
"sha512sum",
|
||||||
"shitbox",
|
"shitbox",
|
||||||
"sleep",
|
"sleep",
|
||||||
"sync",
|
"sync",
|
||||||
|
@ -8,9 +8,9 @@ use sha2::{Digest, Sha256};
|
|||||||
use std::{io, process};
|
use std::{io, process};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Sha224sum;
|
pub struct Sha256sum;
|
||||||
|
|
||||||
impl Cmd for Sha224sum {
|
impl Cmd for Sha256sum {
|
||||||
fn cli(&self) -> clap::Command {
|
fn cli(&self) -> clap::Command {
|
||||||
Command::new("sha256sum")
|
Command::new("sha256sum")
|
||||||
.about("compute and check SHA1 message digest")
|
.about("compute and check SHA1 message digest")
|
||||||
|
53
src/cmd/sha384sum/mod.rs
Normal file
53
src/cmd/sha384sum/mod.rs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
use super::Cmd;
|
||||||
|
use crate::{
|
||||||
|
args,
|
||||||
|
hash::{self, HashType},
|
||||||
|
};
|
||||||
|
use clap::Command;
|
||||||
|
use sha2::{Digest, Sha384};
|
||||||
|
use std::{io, process};
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct Sha384sum;
|
||||||
|
|
||||||
|
impl Cmd for Sha384sum {
|
||||||
|
fn cli(&self) -> clap::Command {
|
||||||
|
Command::new("sha384sum")
|
||||||
|
.about("compute and check SHA1 message digest")
|
||||||
|
.author("Nathan Fisher")
|
||||||
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
|
.args([args::check(), args::file()])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let Some(matches) = matches else {
|
||||||
|
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||||
|
};
|
||||||
|
if let Some(files) = matches.get_many::<String>("file") {
|
||||||
|
let mut erred = 0;
|
||||||
|
for f in files {
|
||||||
|
if matches.get_flag("check") {
|
||||||
|
if f == "-" {
|
||||||
|
return Err(
|
||||||
|
io::Error::new(io::ErrorKind::Other, "no file specified").into()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
hash::check_sums(f, HashType::Sha384, &mut erred)?;
|
||||||
|
} else {
|
||||||
|
let hasher = Sha384::new();
|
||||||
|
let s = hash::compute_hash(f, hasher)?;
|
||||||
|
println!("{s} {f}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if erred > 0 {
|
||||||
|
println!("sha384sum: WARNING: {erred} computed checksum did NOT match");
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn path(&self) -> Option<crate::Path> {
|
||||||
|
Some(crate::Path::UsrBin)
|
||||||
|
}
|
||||||
|
}
|
53
src/cmd/sha512sum/mod.rs
Normal file
53
src/cmd/sha512sum/mod.rs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
use super::Cmd;
|
||||||
|
use crate::{
|
||||||
|
args,
|
||||||
|
hash::{self, HashType},
|
||||||
|
};
|
||||||
|
use clap::Command;
|
||||||
|
use sha2::{Digest, Sha512};
|
||||||
|
use std::{io, process};
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct Sha512sum;
|
||||||
|
|
||||||
|
impl Cmd for Sha512sum {
|
||||||
|
fn cli(&self) -> clap::Command {
|
||||||
|
Command::new("sha512sum")
|
||||||
|
.about("compute and check SHA1 message digest")
|
||||||
|
.author("Nathan Fisher")
|
||||||
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
|
.args([args::check(), args::file()])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let Some(matches) = matches else {
|
||||||
|
return Err(io::Error::new(io::ErrorKind::Other, "no input").into());
|
||||||
|
};
|
||||||
|
if let Some(files) = matches.get_many::<String>("file") {
|
||||||
|
let mut erred = 0;
|
||||||
|
for f in files {
|
||||||
|
if matches.get_flag("check") {
|
||||||
|
if f == "-" {
|
||||||
|
return Err(
|
||||||
|
io::Error::new(io::ErrorKind::Other, "no file specified").into()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
hash::check_sums(f, HashType::Sha512, &mut erred)?;
|
||||||
|
} else {
|
||||||
|
let hasher = Sha512::new();
|
||||||
|
let s = hash::compute_hash(f, hasher)?;
|
||||||
|
println!("{s} {f}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if erred > 0 {
|
||||||
|
println!("sha512sum: WARNING: {erred} computed checksum did NOT match");
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn path(&self) -> Option<crate::Path> {
|
||||||
|
Some(crate::Path::UsrBin)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user