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 92e3351 commit 2952805
Show file tree
Hide file tree
Showing 25 changed files with 384 additions and 4,722 deletions.
67 changes: 24 additions & 43 deletions .cargo/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
# chksum

[![GitHub](https://img.shields.io/badge/github-ferric--bytes%2Fchksum-24292e?style=flat-square&logo=github "GitHub")](https://github.com/ferric-bytes/chksum)
[![docs.rs](https://img.shields.io/docsrs/chksum?style=flat-square&logo=docsdotrs "docs.rs")](https://docs.rs/chksum)
[![Coverage](https://img.shields.io/codecov/c/gh/ferric-bytes/chksum?style=flat-square&logo=codecov "Coverage")](https://app.codecov.io/gh/ferric-bytes/chksum)
[![MSRV](https://img.shields.io/badge/MSRV-1.65.0-informational?style=flat-square "MSRV")](https://github.com/ferric-bytes/chksum/blob/master/Cargo.toml)
[![deps.rs](https://deps.rs/crate/chksum/0.2.2/status.svg?style=flat-square "deps.rs")](https://deps.rs/crate/chksum/0.2.2)
[![GitHub](https://img.shields.io/badge/github-chksum--rs%2Flib-24292e?style=flat-square&logo=github "GitHub")](https://github.com/chksum-rs/lib)
[![Build](https://img.shields.io/github/actions/workflow/status/chksum-rs/lib/rust.yml?branch=master&style=flat-square&logo=github "Build")](https://github.com/chksum-rs/lib/actions/workflows/rust.yml)
[![docs.rs](https://img.shields.io/docsrs/chksum?style=flat-square&logo=docsdotrs "docs.rs")](https://docs.rs/chksum/)
[![MSRV](https://img.shields.io/badge/MSRV-1.70.0-informational?style=flat-square "MSRV")](https://github.com/chksum-rs/lib/blob/master/Cargo.toml)
[![deps.rs](https://deps.rs/crate/chksum/0.3.0/status.svg?style=flat-square "deps.rs")](https://deps.rs/crate/chksum/0.3.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?style=flat-square "LICENSE")](https://github.com/ferric-bytes/chksum/blob/master/LICENSE)
[![LICENSE](https://img.shields.io/github/license/chksum-rs/lib?style=flat-square "LICENSE")](https://github.com/chksum-rs/lib/blob/master/LICENSE)

High-level interface for easy calculation of checksum digest for files, directories, stdin and more.

## Features

- Written in pure Rust
- Easy to use interface
- No unsafe code
- Configurable via Cargo features
An implementation of various hash functions with a straightforward interface for computing digests of bytes, files, directories, and more.

## Setup

Add the following entry to the `dependencies` section of your `Cargo.toml` file:
To use this crate, add the following entry to your `Cargo.toml` file in the `dependencies` section:

```toml
[dependencies]
# ...
chksum = "0.2.2"
chksum = "0.3.0"
```

Alternatively, you can use the [`cargo add`](https://doc.rust-lang.org/cargo/commands/cargo-add.html) subcommand:
Expand All @@ -35,44 +27,33 @@ cargo add chksum

## Usage

Use `chksum` function and `File` as an input.
Use the `chksum` function to calcualate digest of file, directory and so on.

```rust
use std::fs::File;

use chksum::chksum;
use chksum::hash::SHA2_224;
use chksum::sha2_256;

let file = File::open(path)?;
let digest = chksum::<SHA2_224, _>(file)?;
let digest = sha2_256::chksum(file)?;
assert_eq!(
digest.to_hex_lowercase(),
"a39b86d838273f5ff4879c26f85e3cb333bb44d73b24f275bad1a6c6"
"44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
);
```

Alternatively use `ReadDir` as an input.

```rust
use std::fs::read_dir;

use chksum::chksum;
use chksum::hash::SHA2_256;

let dir = read_dir(path)?;
let digest = chksum::<SHA2_256, _>(dir)?;
assert_eq!(
digest.to_hex_lowercase(),
"5c3bfbc8614adc72d3ec0e9b15a1fd1c55cee63e34af5a4ff058eb2eef7d8482"
);
```
For more usage examples, refer to the documentation available at [docs.rs](https://docs.rs/chksum/).

For more usage examples, refer to the documentation available at [docs.rs](https://docs.rs/chksum).
## Hash Algorithms

## Low-level interface
This crate provides implementations for the following hash algorithms:

Check [`chksum-hash`](https://crates.io/crates/chksum-hash) for low-level interface.
* MD5
* SHA-1
* SHA-2
* SHA-2 224
* SHA-2 256
* SHA-2 384
* SHA-2 512

## License

MIT
This crate is licensed under the MIT License.
86 changes: 5 additions & 81 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@ on:
push:
branches:
- master
- dev
paths:
- ".github/workflows/*.yml"
- "Cargo.toml"
- "examples/**.rs"
- "src/**.rs"
- "tests/**.rs"
pull_request:
branches:
- master
- dev
paths:
- ".github/workflows/*.yml"
- "Cargo.toml"
- "examples/**.rs"
- "src/**.rs"
- "tests/**.rs"

jobs:
lint:
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/install@v0.1
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.65.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.65.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.65.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/install@v0.1
with:
crate: cargo-tarpaulin
- name: Run cargo tarpaulin
run: cargo tarpaulin --all-features --engine llvm --fail-under 50 --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
13 changes: 10 additions & 3 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.3.0] - 2023-12-21

### Changed

- Code refactor.

## [0.2.2] - 2023-08-21

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

- Initial release.

[0.2.2]: https://github.com/ferric-bytes/chksum/compare/v0.2.1...v0.2.2
[0.2.1]: https://github.com/ferric-bytes/chksum/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/ferric-bytes/chksum/releases/tag/v0.2.0
[0.3.0]: https://github.com/chksum-rs/lib/releases/tag/v0.3.0
[0.2.2]: https://github.com/chksum-rs/lib/compare/v0.2.1...v0.2.2
[0.2.1]: https://github.com/chksum-rs/lib/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/chksum-rs/lib/releases/tag/v0.2.0
47 changes: 23 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
[package]
name = "chksum"
version = "0.2.2"
version = "0.3.0"
authors = ["Konrad Goławski <konrad@golawski.it>"]
edition = "2021"
rust-version = "1.65.0"
description = "High-level interface for easy calculation of checksum digest for files, directories, stdin and more."
rust-version = "1.70.0"
description = "An implementation of hash functions with a straightforward interface for computing digests of bytes, files, directories, and more."
readme = ".cargo/README.md"
repository = "https://github.com/ferric-bytes/chksum"
repository = "https://github.com/chksum-rs/lib"
license = "MIT"
keywords = ["checksum", "directory-checksum", "file-checksum", "hash"]
keywords = ["checksum", "hash", "directory-checksum", "file-checksum", "stdin-checksum"]
categories = ["algorithms", "cryptography", "filesystem"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
chksum-hash = { version = "0.4.3", default-features = false, features = ["error"] }
is-terminal = "0.4.9"
thiserror = "1.0.44"

[dev-dependencies]
assert_fs = "1.0.13"
thiserror = "1.0.44"
chksum-core = "0.0.0"
chksum-hash = { version = "0.5.0", default-features = false }
chksum-md5 = { version = "0.0.0", optional = true }
chksum-sha1 = { version = "0.0.0", optional = true }
chksum-sha2 = { version = "0.0.0", default-features = false, optional = true }
chksum-reader = { version = "0.0.0", optional = true }
chksum-writer = { version = "0.0.0", optional = true }

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

# compilation
unstable = ["chksum-hash/unstable"]

# algorithms
md5 = ["chksum-hash/md5"]
sha1 = ["chksum-hash/sha1"]
md5 = ["chksum-md5", "chksum-hash/md5"]
sha1 = ["chksum-sha1", "chksum-hash/sha1"]
sha2 = ["sha2-224", "sha2-256", "sha2-384", "sha2-512", "chksum-hash/sha2"]
sha2-224 = ["chksum-hash/sha2-224"]
sha2-256 = ["chksum-hash/sha2-256"]
sha2-384 = ["chksum-hash/sha2-384"]
sha2-512 = ["chksum-hash/sha2-512"]
sha2-224 = ["chksum-sha2/224", "chksum-hash/sha2-224"]
sha2-256 = ["chksum-sha2/256", "chksum-hash/sha2-256"]
sha2-384 = ["chksum-sha2/384", "chksum-hash/sha2-384"]
sha2-512 = ["chksum-sha2/512", "chksum-hash/sha2-512"]

# extra options
reader = ["chksum-reader", "chksum-md5?/reader", "chksum-sha1?/reader", "chksum-sha2?/reader"]
writer = ["chksum-writer", "chksum-md5?/writer", "chksum-sha1?/writer", "chksum-sha2?/writer"]
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 2952805

Please sign in to comment.