Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codetable): automatically include digest dep when needed #360

Merged
merged 3 commits into from
Jan 8, 2024
Merged
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
27 changes: 25 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,36 @@ jobs:
uses: dtolnay/rust-toolchain@stable

- name: Install cargo-deny
run: cargo install cargo-deny
shell: bash
uses: taiki-e/install-action@v2
with:
tool: cargo-deny

- name: Cargo Deny - Check
run: cargo deny check
shell: bash

# todo: run on all crates
cargo-hack-codetable:
name: Cargo Hack - codetable
runs-on: ubuntu-latest
steps:
- name: Checkout Sources
uses: actions/checkout@v4

- name: Install Rust Toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack

- name: Cargo Hack - Check each feature
run: cargo hack check -p multihash-codetable --each-feature
shell: bash
env:
RUSTFLAGS: -D warnings

semver-checks:
runs-on: ubuntu-latest
steps:
Expand Down
16 changes: 15 additions & 1 deletion codetable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ edition = "2021"
[features]
default = ["std"]
std = ["blake2b_simd?/std", "blake2s_simd?/std", "blake3?/std", "digest?/std", "sha1?/std", "sha2?/std", "sha3?/std", "strobe-rs?/std", "ripemd?/std", "multihash-derive/std", "core2/std"]
sha1 = ["dep:sha1"]
sha1 = ["dep:digest", "dep:sha1"]
sha2 = ["dep:digest", "dep:sha2"]
sha3 = ["dep:digest", "dep:sha3"]
ripemd = ["dep:digest", "dep:ripemd"]
strobe = ["dep:strobe-rs"]
blake2b = ["dep:blake2b_simd"]
blake2s = ["dep:blake2s_simd"]
blake3 = ["dep:blake3"]

[dependencies]
blake2b_simd = { version = "1.0.0", default-features = false, optional = true }
Expand Down Expand Up @@ -43,3 +47,13 @@ harness = false
[[test]]
name = "lib"
required-features = ["sha1", "sha2", "sha3", "ripemd", "strobe", "blake2b", "blake2s", "blake3"]

[[example]]
name = "custom_table"
path = "examples/custom_table.rs"
required-features = ["blake2b", "sha2"]

[[example]]
name = "manual_mh"
path = "examples/manual_mh.rs"
required-features = ["sha2"]
6 changes: 3 additions & 3 deletions codetable/src/hasher_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ macro_rules! derive_write {
};
}

#[cfg(any(feature = "blake2b", feature = "blake2s", feature = "blake3"))]
#[cfg(any(feature = "blake2b", feature = "blake2s"))]
macro_rules! derive_hasher_blake {
($module:ident, $name:ident) => {
/// Multihash hasher.
Expand Down Expand Up @@ -81,10 +81,10 @@ pub mod blake2b {
pub mod blake2s {
derive_hasher_blake!(blake2s_simd, Blake2sHasher);

/// 256 bit blake2b hasher.
/// 256 bit blake2s hasher.
pub type Blake2s128 = Blake2sHasher<16>;

/// 512 bit blake2b hasher.
/// 512 bit blake2s hasher.
pub type Blake2s256 = Blake2sHasher<32>;
}

Expand Down
8 changes: 6 additions & 2 deletions codetable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ pub enum Code {
Ripemd320,
}

#[cfg(test)]
#[cfg(all(test, any(feature = "sha2", feature = "sha3")))]
mod tests {
use super::*;
#[cfg(feature = "sha3")]
use crate::hasher_impl::sha3::{Sha3_256, Sha3_512};
use multihash_derive::{Hasher, Multihash, MultihashDigest};
#[cfg(feature = "sha3")]
use multihash_derive::Hasher;
#[cfg(feature = "sha2")]
use multihash_derive::{Multihash, MultihashDigest};

#[test]
#[cfg(feature = "sha3")]
Expand Down