-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7e82c34
Showing
9 changed files
with
563 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# chksum-hash-sha2 | ||
|
||
[![GitHub](https://img.shields.io/badge/github-chksum--rs%2Fhash--sha2-24292e?style=flat-square&logo=github "GitHub")](https://github.com/chksum-rs/hash-sha2) | ||
[![Build](https://img.shields.io/github/actions/workflow/status/chksum-rs/hash-sha2/rust.yml?branch=master&style=flat-square&logo=github "Build")](https://github.com/chksum-rs/hash-sha2/actions/workflows/rust.yml) | ||
[![docs.rs](https://img.shields.io/docsrs/chksum-hash-sha2?style=flat-square&logo=docsdotrs "docs.rs")](https://docs.rs/chksum-hash-sha2/) | ||
[![MSRV](https://img.shields.io/badge/MSRV-1.63.0-informational?style=flat-square "MSRV")](https://github.com/chksum-rs/hash-sha2/blob/master/Cargo.toml) | ||
[![deps.rs](https://deps.rs/crate/chksum-hash-sha2/0.0.0/status.svg?style=flat-square "deps.rs")](https://deps.rs/crate/chksum-hash-sha2/0.0.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/chksum-rs/hash-sha2?style=flat-square "LICENSE")](https://github.com/chksum-rs/hash-sha2/blob/master/LICENSE) | ||
|
||
An implementation of SHA-2 hash algorithms for batch and stream computation. | ||
|
||
## Setup | ||
|
||
To use this crate, add the following entry to your `Cargo.toml` file in the `dependencies` section: | ||
|
||
```toml | ||
[dependencies] | ||
chksum-hash-sha2 = "0.0.0" | ||
``` | ||
|
||
Alternatively, you can use the [`cargo add`](https://doc.rust-lang.org/cargo/commands/cargo-add.html) subcommand: | ||
|
||
```shell | ||
cargo add chksum-hash-sha2 | ||
``` | ||
|
||
## Usage | ||
|
||
Use the `hash` function for batch digest calculation. | ||
|
||
```rust | ||
use chksum_hash_sha2::sha2_256; | ||
|
||
let digest = sha2_256::hash(b"example data"); | ||
assert_eq!( | ||
digest.to_hex_lowercase(), | ||
"44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061" | ||
); | ||
``` | ||
|
||
Use the `default` function to create a hash instance for stream digest calculation. | ||
|
||
```rust | ||
use chksum_hash_sha2::sha2_512; | ||
|
||
let digest = sha2_512::default() | ||
.update("example") | ||
.update(b"data") | ||
.update([0, 1, 2, 3]) | ||
.digest(); | ||
assert_eq!( | ||
digest.to_hex_lowercase(), | ||
"57f35477757af6734892604de3846a97d2cc17cd37068373075e56a4843b3e9c83f9b435beae9fcf1da590e73e62fe20468f52ff13b095241fec77884086b090" | ||
); | ||
``` | ||
|
||
For more usage examples, refer to the documentation available at [docs.rs](https://docs.rs/chksum-hash-sha2/). | ||
|
||
## Features | ||
|
||
Cargo features are used to enable or disable specific algorithm functions. | ||
|
||
* `224` enables SHA-2 224, accessible via the `sha2_224` module, | ||
* `256` enables SHA-2 256, accessible via the `sha2_256` module, | ||
* `384` enables SHA-2 384, accessible via the `sha2_384` module, | ||
* `512` enables SHA-2 512, accessible via the `sha2_512` module. | ||
|
||
By default all of them are enabled. | ||
|
||
To customize your setup, turn off the default features and enable only those that you want in your `Cargo.toml` file: | ||
|
||
```toml | ||
[dependencies] | ||
chksum-hash-sha2 = { version = "0.0.0", default-features = no, features = ["256", "512"] } | ||
``` | ||
|
||
Alternatively, you can use the [`cargo add`](https://doc.rust-lang.org/cargo/commands/cargo-add.html) subcommand: | ||
|
||
```shell | ||
cargo add chksum-hash-sha2 --no-default-features --features 256,512 | ||
``` | ||
|
||
## License | ||
|
||
This crate is licensed under the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
name: Rust | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
permissions: | ||
contents: read | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
paths: | ||
- ".github/workflows/*.yml" | ||
- "Cargo.toml" | ||
- "src/**.rs" | ||
pull_request: | ||
branches: | ||
- master | ||
paths: | ||
- ".github/workflows/*.yml" | ||
- "Cargo.toml" | ||
- "src/**.rs" | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
name: Lint | ||
permissions: | ||
checks: write | ||
contents: write | ||
pull-requests: write | ||
steps: | ||
- name: Repository checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: nightly | ||
default: true | ||
profile: minimal | ||
components: rustfmt, clippy | ||
- name: Run cargo fmt | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: fmt | ||
args: --check --verbose | ||
- name: Run cargo clippy | ||
uses: actions-rs/clippy-check@v1 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
args: --all-features -- --deny clippy::cargo | ||
|
||
build-and-test-linux: | ||
needs: | ||
- lint | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
toolchain: [1.63.0, stable, nightly] | ||
name: "Build and test (OS: Linux, Toolchain: ${{ matrix.toolchain }})" | ||
steps: | ||
- name: Repository checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: ${{ matrix.toolchain }} | ||
default: true | ||
profile: minimal | ||
- name: Run cargo build | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: build | ||
args: --all-features --verbose | ||
- name: Run cargo test | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
args: --all-features --verbose | ||
|
||
build-and-test-macos: | ||
needs: | ||
- lint | ||
runs-on: macos-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
toolchain: [1.63.0, stable, nightly] | ||
name: "Build and test (OS: MacOS, Toolchain: ${{ matrix.toolchain }})" | ||
steps: | ||
- name: Repository checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: ${{ matrix.toolchain }} | ||
default: true | ||
profile: minimal | ||
- name: Run cargo build | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: build | ||
args: --all-features --verbose | ||
- name: Run cargo test | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
args: --all-features --verbose | ||
|
||
build-and-test-windows: | ||
needs: | ||
- lint | ||
runs-on: windows-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
toolchain: [1.63.0, stable, nightly] | ||
name: "Build and test (OS: Windows, Toolchain: ${{ matrix.toolchain }})" | ||
steps: | ||
- name: Repository checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Rust | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: ${{ matrix.toolchain }} | ||
default: true | ||
profile: minimal | ||
- name: Run cargo build | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: build | ||
args: --all-features --verbose | ||
- name: Run cargo test | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
args: --all-features --verbose | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Cargo | ||
Cargo.lock | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Changelog | ||
|
||
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.0.0] - 2023-12-21 | ||
|
||
### Added | ||
|
||
- Initial release. | ||
|
||
[0.0.0]: https://github.com/chksum-rs/hash-sha2/releases/tag/v0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[package] | ||
name = "chksum-hash-sha2" | ||
version = "0.0.0" | ||
authors = ["Konrad Goławski <konrad@golawski.it>"] | ||
edition = "2021" | ||
rust-version = "1.63.0" | ||
description = "An implementation of SHA-2 hash algorithms for batch and stream computation." | ||
readme = ".cargo/README.md" | ||
repository = "https://github.com/chksum-rs/hash-sha2" | ||
license = "MIT" | ||
keywords = ["checksum", "digest", "hash", "sha2", "sha-2"] | ||
categories = ["algorithms", "cryptography"] | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
rustdoc-args = ["--cfg", "docsrs"] | ||
|
||
[dependencies] | ||
chksum-hash-sha2-224 = { version = "0.0.0", optional = true } | ||
chksum-hash-sha2-256 = { version = "0.0.0", optional = true } | ||
chksum-hash-sha2-384 = { version = "0.0.0", optional = true } | ||
chksum-hash-sha2-512 = { version = "0.0.0", optional = true } | ||
|
||
[features] | ||
default = ["224", "256", "384", "512"] | ||
224 = ["chksum-hash-sha2-224"] | ||
256 = ["chksum-hash-sha2-256"] | ||
384 = ["chksum-hash-sha2-384"] | ||
512 = ["chksum-hash-sha2-512"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 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 | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# chksum-hash-sha2 | ||
|
||
[![crates.io](https://img.shields.io/crates/v/chksum-hash-sha2?style=flat-square&logo=rust "crates.io")](https://crates.io/crates/chksum-hash-sha2) | ||
[![Build](https://img.shields.io/github/actions/workflow/status/chksum-rs/hash-sha2/rust.yml?branch=master&style=flat-square&logo=github "Build")](https://github.com/chksum-rs/hash-sha2/actions/workflows/rust.yml) | ||
[![docs.rs](https://img.shields.io/docsrs/chksum-hash-sha2?style=flat-square&logo=docsdotrs "docs.rs")](https://docs.rs/chksum-hash-sha2/) | ||
[![MSRV](https://img.shields.io/badge/MSRV-1.63.0-informational?style=flat-square "MSRV")](https://github.com/chksum-rs/hash-sha2/blob/master/Cargo.toml) | ||
[![deps.rs](https://deps.rs/crate/chksum-hash-sha2/0.0.0/status.svg?style=flat-square "deps.rs")](https://deps.rs/crate/chksum-hash-sha2/0.0.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/chksum-rs/hash-sha2?style=flat-square "LICENSE")](https://github.com/chksum-rs/hash-sha2/blob/master/LICENSE) | ||
|
||
An implementation of SHA-2 hash algorithms for batch and stream computation. | ||
|
||
## Setup | ||
|
||
To use this crate, add the following entry to your `Cargo.toml` file in the `dependencies` section: | ||
|
||
```toml | ||
[dependencies] | ||
chksum-hash-sha2 = "0.0.0" | ||
``` | ||
|
||
Alternatively, you can use the [`cargo add`](https://doc.rust-lang.org/cargo/commands/cargo-add.html) subcommand: | ||
|
||
```shell | ||
cargo add chksum-hash-sha2 | ||
``` | ||
|
||
## Usage | ||
|
||
Use the `hash` function for batch digest calculation. | ||
|
||
```rust | ||
use chksum_hash_sha2::sha2_256; | ||
|
||
let digest = sha2_256::hash(b"example data"); | ||
assert_eq!( | ||
digest.to_hex_lowercase(), | ||
"44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061" | ||
); | ||
``` | ||
|
||
Use the `default` function to create a hash instance for stream digest calculation. | ||
|
||
```rust | ||
use chksum_hash_sha2::sha2_512; | ||
|
||
let digest = sha2_512::default() | ||
.update("example") | ||
.update(b"data") | ||
.update([0, 1, 2, 3]) | ||
.digest(); | ||
assert_eq!( | ||
digest.to_hex_lowercase(), | ||
"57f35477757af6734892604de3846a97d2cc17cd37068373075e56a4843b3e9c83f9b435beae9fcf1da590e73e62fe20468f52ff13b095241fec77884086b090" | ||
); | ||
``` | ||
|
||
For more usage examples, refer to the documentation available at [docs.rs](https://docs.rs/chksum-hash-sha2/). | ||
|
||
## Features | ||
|
||
Cargo features are used to enable or disable specific algorithm functions. | ||
|
||
* `224` enables SHA-2 224, accessible via the `sha2_224` module, | ||
* `256` enables SHA-2 256, accessible via the `sha2_256` module, | ||
* `384` enables SHA-2 384, accessible via the `sha2_384` module, | ||
* `512` enables SHA-2 512, accessible via the `sha2_512` module. | ||
|
||
By default all of them are enabled. | ||
|
||
To customize your setup, turn off the default features and enable only those that you want in your `Cargo.toml` file: | ||
|
||
```toml | ||
[dependencies] | ||
chksum-hash-sha2 = { version = "0.0.0", default-features = no, features = ["256", "512"] } | ||
``` | ||
|
||
Alternatively, you can use the [`cargo add`](https://doc.rust-lang.org/cargo/commands/cargo-add.html) subcommand: | ||
|
||
```shell | ||
cargo add chksum-hash-sha2 --no-default-features --features 256,512 | ||
``` | ||
|
||
## License | ||
|
||
This crate is licensed under the MIT License. |
Oops, something went wrong.