Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ventaquil committed Dec 21, 2023
1 parent 5858280 commit e638471
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 293 deletions.
57 changes: 29 additions & 28 deletions .cargo/README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
# chksum-cli

[![GitHub](https://img.shields.io/badge/github-ferric--bytes%2Fchksum--cli-24292e?style=flat-square&logo=github "GitHub")](https://github.com/ferric-bytes/chksum-cli)
[![Coverage](https://img.shields.io/codecov/c/gh/ferric-bytes/chksum-cli?style=flat-square&logo=codecov "Coverage")](https://app.codecov.io/gh/ferric-bytes/chksum-cli)
[![MSRV](https://img.shields.io/badge/MSRV-1.66.0-informational?style=flat-square "MSRV")](https://github.com/ferric-bytes/chksum-cli/blob/master/Cargo.toml)
[![deps.rs](https://deps.rs/crate/chksum-cli/0.3.2/status.svg?style=flat-square "deps.rs")](https://deps.rs/crate/chksum-cli/0.3.2)
[![GitHub](https://img.shields.io/badge/github-chksum--rs%2Fcli-24292e?style=flat-square&logo=github "GitHub")](https://github.com/chksum-rs/cli)
[![Build](https://img.shields.io/github/actions/workflow/status/chksum-rs/cli/rust.yml?branch=master&style=flat-square&logo=github "Build")](https://github.com/chksum-rs/cli/actions/workflows/rust.yml)
[![MSRV](https://img.shields.io/badge/MSRV-1.70.0-informational?style=flat-square "MSRV")](https://github.com/chksum-rs/cli/blob/master/Cargo.toml)
[![deps.rs](https://deps.rs/crate/chksum/0.4.0/status.svg?style=flat-square "deps.rs")](https://deps.rs/crate/chksum/0.4.0)
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg?style=flat-square "unsafe forbidden")](https://github.com/rust-secure-code/safety-dance)
[![LICENSE](https://img.shields.io/github/license/ferric-bytes/chksum-cli?style=flat-square "LICENSE")](https://github.com/ferric-bytes/chksum-cli/blob/master/LICENSE)
[![LICENSE](https://img.shields.io/github/license/chksum-rs/cli?style=flat-square "LICENSE")](https://github.com/chksum-rs/cli/blob/master/LICENSE)

A simple checksum calculator.

## Motivation

There are variety of tools that allows calculate hash digests.

However tools like `md5sum`, `sha1sum`, `b2sum`, `sha224sum` and others offer only file-based checksums.
Various tools like `md5sum`, `sha1sum`, `b2sum`, `sha224sum`, etc., allow users to calculate file-based hash digests. However, these tools focus on file-level checksums, making it cumbersome to handle scenarios like calculating digests on-the-fly while writing data. This motivated the creation of `chksum` to offer a simplified interface for such use cases.

```shell
find dir/ -type f | sort | xargs cat | sha224sum
```

Instead you can just use `chksum` with preffered hash algorithm.
With `chksum`, you can achieve the same result with your preferred hash algorithm:

```sh
chksum sha2-224 dir/
```

## Features
## Key Features

- Written in pure Rust
- No unsafe code
- Configurable via Cargo features
- Multithread
* Implemented in pure Rust
* No unsafe code
* Configurable via Cargo features
* Multithreaded

## Installation

Use [`cargo install`](https://doc.rust-lang.org/cargo/commands/cargo-install.html) to install `chksum` binary in `$HOME/.cargo/bin` directory.
Install the `chksum` binary using [`cargo install`](https://doc.rust-lang.org/cargo/commands/cargo-install.html):

```shell
cargo install chksum-cli
```

## Usage

### General Help

```shell
$ chksum help
A simple checksum calculator.
Expand All @@ -63,6 +63,8 @@ Options:
-V, --version Print version
```

### Help for a Specific Algorithm

```shell
$ chksum help sha2-224
Calculate SHA-2 224 digest
Expand All @@ -78,21 +80,21 @@ Options:
-h, --help Print help
```

### File
### File Processing

```shell
$ chksum sha2-224 LICENSE
LICENSE: 99258bca0d23c69388dd53412f1009132753b89459359a401a6ed158
```

### Directory
### Directory Processing

```shell
$ chksum sha1 src/
src/: 03e4ae615c034f5db47c72bd5c6c9e5bf450a2bd
```

### Standard input
### Standard Input Processing

```shell
$ echo -n admin1 | chksum md5 --stdin
Expand All @@ -101,17 +103,17 @@ $ echo -n admin1 | chksum md5 --stdin

## Library

Check [`chksum`](https://crates.io/crates/chksum) crate to see the library that allows you to calculate digests of files and directories with easy-to-use interface.
Check out the [`chksum`](https://crates.io/crates/chksum) crate to see the library that allows you to calculate digests of files and directories with an easy-to-use interface.

## Hash algorithms
## Hash Algorithms

Implemented hash algorithms:
This binary provides implementations for the following hash algorithms:

* MD5 - [RFC 1321: The MD5 Message-Digest Algorithm](https://tools.ietf.org/html/rfc1321)
* SHA-1 - [RFC 3174: US Secure Hash Algorithm 1 (SHA1)](https://tools.ietf.org/html/rfc3174)
* SHA-2 family (SHA-224, SHA-256, SHA-386, SHA-512) - [FIPS PUB 180-4: Secure Hash Standard](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf)

## Feature flags
## Features

### Algorithms

Expand All @@ -123,19 +125,18 @@ Implemented hash algorithms:
* `sha2-384`: Enables only SHA-2 384 hash algorithm.
* `sha2-512`: Enables only SHA-2 512 hash algorithm.

By default all of them are enabled.
By default, all of them are enabled.

### Options
### Extra Options

* `color`: Enables colored output.
* `unstable`: Enables unstable options.

By default only `color` is enabled.
By default, all of them are enabled.

## Disclaimer

Code is under development. The interface may change in the future.
The code is under development, and the interface may change in the future.

## License

MIT
This crate is licensed under the MIT License.
82 changes: 3 additions & 79 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
push:
branches:
- master
- dev
paths:
- ".github/workflows/*.yml"
- "Cargo.toml"
Expand All @@ -19,7 +18,6 @@ on:
pull_request:
branches:
- master
- dev
paths:
- ".github/workflows/*.yml"
- "Cargo.toml"
Expand Down Expand Up @@ -55,55 +53,14 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features -- --deny clippy::cargo

deny:
runs-on: ubuntu-latest
name: Deny
steps:
- name: Repository checkout
uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true
profile: minimal
- name: Install cargo deny
uses: actions-rs/[email protected]
with:
crate: cargo-deny
- name: Run cargo deny
uses: actions-rs/cargo@v1
with:
command: deny
args: --all-features check

security-audit:
name: Security Audit
runs-on: ubuntu-latest
steps:
- name: Repository checkout
uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
default: true
profile: minimal
- name: Run audit check
uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

build-and-test-linux:
needs:
- deny
- lint
- security-audit
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
toolchain: [1.66.0, stable, nightly]
toolchain: [1.70.0, stable, nightly]
name: "Build and test (OS: Linux, Toolchain: ${{ matrix.toolchain }})"
steps:
- name: Repository checkout
Expand All @@ -127,14 +84,12 @@ jobs:

build-and-test-macos:
needs:
- deny
- lint
- security-audit
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
toolchain: [1.66.0, stable, nightly]
toolchain: [1.70.0, stable, nightly]
name: "Build and test (OS: MacOS, Toolchain: ${{ matrix.toolchain }})"
steps:
- name: Repository checkout
Expand All @@ -158,14 +113,12 @@ jobs:

build-and-test-windows:
needs:
- deny
- lint
- security-audit
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
toolchain: [1.66.0, stable, nightly]
toolchain: [1.70.0, stable, nightly]
name: "Build and test (OS: Windows, Toolchain: ${{ matrix.toolchain }})"
steps:
- name: Repository checkout
Expand All @@ -186,32 +139,3 @@ jobs:
with:
command: test
args: --all-features --verbose

coverage:
needs:
- deny
- lint
- security-audit
runs-on: ubuntu-latest
name: Coverage
steps:
- name: Repository checkout
uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true
profile: minimal
- name: Install cargo tarpaulin
uses: actions-rs/[email protected]
with:
crate: cargo-tarpaulin
- name: Run cargo tarpaulin
run: cargo tarpaulin --all-features --engine llvm --fail-under 50 --follow-exec --ignore-tests --out xml --timeout 120
- name: Upload to codecov.io
if: ${{ always() }}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
16 changes: 12 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.0] - 2023-12-21

### Changed

- Code refactor.

## [0.3.2] - 2023-08-21

### Added
Expand Down Expand Up @@ -60,7 +66,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial release.

[0.3.2]: https://github.com/ferric-bytes/chksum-cli/compare/v0.3.1...v0.3.2
[0.3.1]: https://github.com/ferric-bytes/chksum-cli/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/ferric-bytes/chksum-cli/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/ferric-bytes/chksum-cli/releases/tag/v0.2.0
[0.4.0]: https://github.com/chksum-rs/cli/compare/v0.3.2...v0.4.0
[0.3.2]: https://github.com/chksum-rs/cli/compare/v0.3.1...v0.3.2
[0.3.2]: https://github.com/chksum-rs/cli/compare/v0.3.1...v0.3.2
[0.3.1]: https://github.com/chksum-rs/cli/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/chksum-rs/cli/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/chksum-rs/cli/releases/tag/v0.2.0
21 changes: 9 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "chksum-cli"
version = "0.3.2"
version = "0.4.0"
authors = ["Konrad Goławski <[email protected]>"]
edition = "2021"
rust-version = "1.66.0"
rust-version = "1.70.0"
description = "A simple checksum calculator."
readme = ".cargo/README.md"
repository = "https://github.com/ferric-bytes/chksum-cli"
repository = "https://github.com/chksum-rs/cli"
license = "MIT"
keywords = ["checksum", "digest", "directory-checksum", "file-checksum", "hash"]
categories = ["command-line-utilities", "cryptography", "filesystem"]
Expand All @@ -19,31 +19,28 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
anyhow = "1.0.72"
chksum = "0.2.2"
clap = { version = "4.3.19", features = ["cargo", "derive", "wrap_help", "unicode"] }
colored = { version = "2.0.4", optional = true }
anyhow = "1.0.76"
chksum = { version = "0.3.0", default-features = false }
clap = { version = "4.4.11", features = ["cargo", "derive", "wrap_help", "unicode"] }
colored = { version = "2.1.0", optional = true }
exitcode = "1.1.2"
rayon = "1.7.0"

[dev-dependencies]
assert_cmd = { version = "2.0.12", features = ["color-auto"] }
assert_fs = { version = "1.0.13", features = ["color-auto"] }
thiserror = "1.0.44"
thiserror = "1.0.51"

[features]
default = [
# compilation
"color",
# algorithms
"md5",
"sha1",
"sha2",
"md5", "sha1", "sha2",
]

# compilation
color = ["colored"]
unstable = ["chksum/unstable"]

# algorithms
md5 = ["chksum/md5"]
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Konrad Goławski
Copyright (c) 2020-2023 Konrad Goławski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit e638471

Please sign in to comment.