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

feat!: split crates into multiple to isolate breaking changes #272

Merged
merged 39 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7f3c30d
Initial split of crates
thomaseizinger Jan 31, 2023
3932079
Deprecate export of `Multihash`
thomaseizinger Jan 31, 2023
8ca3071
inline synstructure macro
thomaseizinger Jan 31, 2023
91f96c6
Deprecate old macro name in favor of new one
thomaseizinger Jan 31, 2023
d0e8215
Remove `derive` feature flag
thomaseizinger Jan 31, 2023
bcf8135
Remove unnecessary `pub` qualifier
thomaseizinger Jan 31, 2023
9cee44e
Remove unnecessary feature-gated import
thomaseizinger Jan 31, 2023
c1e5355
Deprecate `serde-codec`
thomaseizinger Jan 31, 2023
2dbeded
Remove git blame file
thomaseizinger Jan 31, 2023
f3a4c8b
Run rustfmt
thomaseizinger Mar 21, 2023
d9aa346
Reduce number of `cfg`s
thomaseizinger Mar 21, 2023
2bc4101
Remove `Result` type
thomaseizinger Mar 21, 2023
2a96940
Make `Error` opaque
thomaseizinger Mar 21, 2023
aab78df
Introduce `multihash-derive-impl` crate
thomaseizinger Mar 21, 2023
e2e2229
Fix clippy lint
thomaseizinger Mar 21, 2023
c32ce92
Only build multihash for no_std
thomaseizinger Mar 21, 2023
cb0d728
Update docs
thomaseizinger Mar 21, 2023
abbb7eb
Update docs for multihash-codetable
thomaseizinger Mar 21, 2023
c502465
Remove outdated docs
thomaseizinger Mar 21, 2023
e67be12
Replace macro tests with trybuild
thomaseizinger Mar 21, 2023
4d3048c
Remove unused feature `std` from `multihash`
thomaseizinger Mar 21, 2023
5a97fdc
Export deprecated macro name
thomaseizinger Mar 21, 2023
0b85ce9
Reduce diff
thomaseizinger Mar 21, 2023
960ec0e
Minimize diff and fix cargo metadata
thomaseizinger Mar 21, 2023
72601b1
Minimize diff
thomaseizinger Mar 21, 2023
b25bfcb
Remove `extern crate core`
thomaseizinger Mar 22, 2023
c0925a8
Use `dep:` consistently
thomaseizinger Mar 22, 2023
0cb5c77
Use uniform way of referring to error type
thomaseizinger Mar 22, 2023
55759e5
Make everything work on `no_std` again
thomaseizinger Mar 22, 2023
9a679cc
Add back serde support for `Code`
thomaseizinger Mar 22, 2023
c44bfb2
Reintroduce feature-flags in `multihash-codetable`
thomaseizinger Mar 22, 2023
40ea00c
Only use `serde` feature flag
thomaseizinger Mar 23, 2023
eb955f2
Restore old feature flags
thomaseizinger Mar 23, 2023
4f4e34d
Merge imports
thomaseizinger Mar 23, 2023
65b2ebc
Remove unnecessary qualification
thomaseizinger Mar 23, 2023
efc5caa
Restore identity hasher
thomaseizinger Mar 29, 2023
d48ac2c
Correctly feature-gate export
thomaseizinger Mar 29, 2023
b73894c
Replace imports with full-qualified references to avoid `cfg`s
thomaseizinger Mar 30, 2023
f5e46ca
Fix test
thomaseizinger Mar 30, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --no-default-features --package multihash --target thumbv6m-none-eabi
args: --no-default-features --workspace --target thumbv6m-none-eabi

coverage:
name: Code Coverage
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ rust-version = "1.59"
default = ["std"]
std = ["unsigned-varint/std", "alloc"]
alloc = []
arb = ["quickcheck", "rand", "arbitrary"]
arb = ["dep:quickcheck", "dep:rand", "dep:arbitrary"]
scale-codec = ["dep:parity-scale-codec"]
serde-codec = ["serde"] # Deprecated, don't use.
serde-codec = ["dep:serde"] # Deprecated, don't use.
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
serde = ["dep:serde", "dep:serde-big-array"]

[dependencies]
Expand Down
32 changes: 23 additions & 9 deletions codetable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,27 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["std"]
std = ["blake2b_simd?/std", "blake2s_simd?/std", "blake3?/std", "digest?/std", "sha-1?/std", "sha2?/std", "sha3?/std", "strobe-rs?/std", "ripemd?/std", "multihash-derive/std", "core2/std"]
sha1 = ["dep:sha-1"]
strobe = ["dep:strobe-rs"]
blake2b = ["dep:blake2b_simd"]
blake2s = ["dep:blake2s_simd"]

[dependencies]
blake2b_simd = { version = "1.0.0", default-features = false }
blake2s_simd = { version = "1.0.0", default-features = false }
blake3 = { version = "1.2.0", default-features = false }
digest = { version = "0.10.1", default-features = false }
sha-1 = { version = "0.10.0", default-features = false }
sha-2 = { version = "0.10.0", default-features = false, package = "sha2" }
sha-3 = { version = "0.10.0", default-features = false, package = "sha3" }
strobe-rs = { version = "0.7.0", default-features = false }
ripemd-rs = { package = "ripemd", version = "0.1.1"}
blake2b_simd = { version = "1.0.0", default-features = false, optional = true }
blake2s_simd = { version = "1.0.0", default-features = false, optional = true }
blake3 = { version = "1.2.0", default-features = false, optional = true }
digest = { version = "0.10.1", default-features = false, optional = true }
sha-1 = { version = "0.10.0", default-features = false, optional = true }
sha2 = { version = "0.10.0", default-features = false, optional = true }
sha3 = { version = "0.10.0", default-features = false, optional = true }
strobe-rs = { version = "0.7.0", default-features = false, optional = true }
ripemd = { version = "0.1.1", default-features = false, optional = true }
multihash-derive = { version = "0.8.0", path = "../derive", default-features = false }
core2 = { version = "0.4.0", default-features = false }
serde = { version = "1.0.158", features = ["derive"], optional = true }

[dev-dependencies]
hex = "0.4.2"
Expand All @@ -29,3 +39,7 @@ rand = "0.8.5"
[[bench]]
name = "multihash"
harness = false

[[test]]
name = "lib"
required-features = ["sha1", "sha2", "sha3", "ripemd", "strobe", "blake2b", "blake2s", "blake3"]
43 changes: 29 additions & 14 deletions codetable/src/hasher_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use multihash_derive::Hasher;

use std::io;
use core2::io;

macro_rules! derive_write {
($name:ident) => {
Expand All @@ -17,6 +17,7 @@ macro_rules! derive_write {
};
}

#[cfg(any(feature = "blake2b", feature = "blake2s", feature = "blake3"))]
macro_rules! derive_hasher_blake {
($module:ident, $name:ident) => {
/// Multihash hasher.
Expand Down Expand Up @@ -60,6 +61,7 @@ macro_rules! derive_hasher_blake {
};
}

#[cfg(feature = "blake2b")]
pub mod blake2b {
use super::*;

Expand All @@ -72,6 +74,7 @@ pub mod blake2b {
pub type Blake2b512 = Blake2bHasher<64>;
}

#[cfg(feature = "blake2s")]
pub mod blake2s {
use super::*;

Expand All @@ -84,6 +87,7 @@ pub mod blake2s {
pub type Blake2s256 = Blake2sHasher<32>;
}

#[cfg(feature = "blake3")]
pub mod blake3 {
use super::*;

Expand Down Expand Up @@ -135,6 +139,12 @@ pub mod blake3 {
pub type Blake3_256 = Blake3Hasher<32>;
}

#[cfg(any(
feature = "sha1",
feature = "sha2",
feature = "sha3",
feature = "ripemd"
))]
macro_rules! derive_rustcrypto_hasher {
($module:ty, $name:ident, $size:expr) => {
/// Multihash hasher.
Expand Down Expand Up @@ -187,40 +197,44 @@ macro_rules! derive_rustcrypto_hasher {
};
}

#[cfg(feature = "sha1")]
pub mod sha1 {
use super::*;

derive_rustcrypto_hasher!(::sha1::Sha1, Sha1, 20);
}

#[cfg(feature = "sha2")]
pub mod sha2 {
use super::*;

derive_rustcrypto_hasher!(sha_2::Sha256, Sha2_256, 32);
derive_rustcrypto_hasher!(sha_2::Sha512, Sha2_512, 64);
derive_rustcrypto_hasher!(::sha2::Sha256, Sha2_256, 32);
derive_rustcrypto_hasher!(::sha2::Sha512, Sha2_512, 64);
}

#[cfg(feature = "sha3")]
pub mod sha3 {
use super::*;

derive_rustcrypto_hasher!(sha_3::Sha3_224, Sha3_224, 28);
derive_rustcrypto_hasher!(sha_3::Sha3_256, Sha3_256, 32);
derive_rustcrypto_hasher!(sha_3::Sha3_384, Sha3_384, 48);
derive_rustcrypto_hasher!(sha_3::Sha3_512, Sha3_512, 64);
derive_rustcrypto_hasher!(::sha3::Sha3_224, Sha3_224, 28);
derive_rustcrypto_hasher!(::sha3::Sha3_256, Sha3_256, 32);
derive_rustcrypto_hasher!(::sha3::Sha3_384, Sha3_384, 48);
derive_rustcrypto_hasher!(::sha3::Sha3_512, Sha3_512, 64);

derive_rustcrypto_hasher!(sha_3::Keccak224, Keccak224, 28);
derive_rustcrypto_hasher!(sha_3::Keccak256, Keccak256, 32);
derive_rustcrypto_hasher!(sha_3::Keccak384, Keccak384, 48);
derive_rustcrypto_hasher!(sha_3::Keccak512, Keccak512, 64);
derive_rustcrypto_hasher!(::sha3::Keccak224, Keccak224, 28);
derive_rustcrypto_hasher!(::sha3::Keccak256, Keccak256, 32);
derive_rustcrypto_hasher!(::sha3::Keccak384, Keccak384, 48);
derive_rustcrypto_hasher!(::sha3::Keccak512, Keccak512, 64);
}

#[cfg(feature = "ripemd")]
pub mod ripemd {

use super::*;

derive_rustcrypto_hasher!(ripemd_rs::Ripemd160, Ripemd160, 20);
derive_rustcrypto_hasher!(ripemd_rs::Ripemd256, Ripemd256, 32);
derive_rustcrypto_hasher!(ripemd_rs::Ripemd320, Ripemd320, 40);
derive_rustcrypto_hasher!(::ripemd::Ripemd160, Ripemd160, 20);
derive_rustcrypto_hasher!(::ripemd::Ripemd256, Ripemd256, 32);
derive_rustcrypto_hasher!(::ripemd::Ripemd320, Ripemd320, 40);
}

pub mod identity {
Expand Down Expand Up @@ -273,6 +287,7 @@ pub mod identity {
pub type Identity256 = IdentityHasher<32>;
}

#[cfg(feature = "strobe")]
pub mod strobe {
use super::*;
use strobe_rs::{SecParam, Strobe};
Expand Down
42 changes: 40 additions & 2 deletions codetable/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
#![cfg_attr(not(feature = "std"), no_std)]

mod hasher_impl;

use multihash_derive::MultihashDigest;

#[cfg(feature = "blake2b")]
pub use crate::hasher_impl::blake2b::{Blake2b256, Blake2b512, Blake2bHasher};
#[cfg(feature = "blake2s")]
pub use crate::hasher_impl::blake2s::{Blake2s128, Blake2s256, Blake2sHasher};
#[cfg(feature = "blake3")]
pub use crate::hasher_impl::blake3::{Blake3Hasher, Blake3_256};
pub use crate::hasher_impl::identity::{Identity256, IdentityHasher};
#[cfg(feature = "ripemd")]
pub use crate::hasher_impl::ripemd::{Ripemd160, Ripemd256, Ripemd320};
#[cfg(feature = "sha1")]
pub use crate::hasher_impl::sha1::Sha1;
#[cfg(feature = "sha2")]
pub use crate::hasher_impl::sha2::{Sha2_256, Sha2_512};
pub use crate::hasher_impl::sha3::{Keccak224, Keccak256, Keccak384, Keccak512};
pub use crate::hasher_impl::sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512};
#[cfg(feature = "sha3")]
pub use crate::hasher_impl::sha3::{
Keccak224, Keccak256, Keccak384, Keccak512, Sha3_224, Sha3_256, Sha3_384, Sha3_512,
};
#[cfg(feature = "strobe")]
pub use crate::hasher_impl::strobe::{Strobe256, Strobe512, StrobeHasher};

/// Default (cryptographically secure) Multihash implementation.
Expand All @@ -19,61 +30,80 @@ pub use crate::hasher_impl::strobe::{Strobe256, Strobe512, StrobeHasher};
/// algorithms. See the [`multihash-derive`] crate for more information.
///
/// [`multihash-derive`]: https://docs.rs/multihash-derive
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Debug, Eq, MultihashDigest, PartialEq)]
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
#[mh(alloc_size = 64)]
pub enum Code {
/// SHA-256 (32-byte hash size)
#[cfg(feature = "sha2")]
#[mh(code = 0x12, hasher = crate::Sha2_256)]
Sha2_256,
/// SHA-512 (64-byte hash size)
#[cfg(feature = "sha2")]
#[mh(code = 0x13, hasher = crate::Sha2_512)]
Sha2_512,
/// SHA3-224 (28-byte hash size)
#[cfg(feature = "sha3")]
#[mh(code = 0x17, hasher = crate::Sha3_224)]
Sha3_224,
/// SHA3-256 (32-byte hash size)
#[cfg(feature = "sha3")]
#[mh(code = 0x16, hasher = crate::Sha3_256)]
Sha3_256,
/// SHA3-384 (48-byte hash size)
#[cfg(feature = "sha3")]
#[mh(code = 0x15, hasher = crate::Sha3_384)]
Sha3_384,
/// SHA3-512 (64-byte hash size)
#[cfg(feature = "sha3")]
#[mh(code = 0x14, hasher = crate::Sha3_512)]
Sha3_512,
/// Keccak-224 (28-byte hash size)
#[cfg(feature = "sha2")]
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
#[mh(code = 0x1a, hasher = crate::Keccak224)]
Keccak224,
/// Keccak-256 (32-byte hash size)
#[cfg(feature = "sha2")]
#[mh(code = 0x1b, hasher = crate::Keccak256)]
Keccak256,
/// Keccak-384 (48-byte hash size)
#[cfg(feature = "sha3")]
#[mh(code = 0x1c, hasher = crate::Keccak384)]
Keccak384,
/// Keccak-512 (64-byte hash size)
#[cfg(feature = "sha3")]
#[mh(code = 0x1d, hasher = crate::Keccak512)]
Keccak512,
/// BLAKE2b-256 (32-byte hash size)
#[cfg(feature = "blake2b")]
#[mh(code = 0xb220, hasher = crate::Blake2b256)]
Blake2b256,
/// BLAKE2b-512 (64-byte hash size)
#[cfg(feature = "blake2b")]
#[mh(code = 0xb240, hasher = crate::Blake2b512)]
Blake2b512,
/// BLAKE2s-128 (16-byte hash size)
#[cfg(feature = "blake2s")]
#[mh(code = 0xb250, hasher = crate::Blake2s128)]
Blake2s128,
/// BLAKE2s-256 (32-byte hash size)
#[cfg(feature = "blake2s")]
#[mh(code = 0xb260, hasher = crate::Blake2s256)]
Blake2s256,
/// BLAKE3-256 (32-byte hash size)
#[cfg(feature = "blake2s")]
#[mh(code = 0x1e, hasher = crate::Blake3_256)]
Blake3_256,
/// RIPEMD-160 (20-byte hash size)
#[cfg(feature = "ripemd")]
#[mh(code = 0x1053, hasher = crate::Ripemd160)]
Ripemd160,
/// RIPEMD-256 (32-byte hash size)
#[cfg(feature = "ripemd")]
#[mh(code = 0x1054, hasher = crate::Ripemd256)]
Ripemd256,
/// RIPEMD-320 (40-byte hash size)
#[cfg(feature = "ripemd")]
#[mh(code = 0x1055, hasher = crate::Ripemd320)]
Ripemd320,
// The following hashes are not cryptographically secure hashes and are not enabled by default
Expand All @@ -90,6 +120,7 @@ mod tests {
use multihash_derive::{Hasher, Multihash};

#[test]
#[cfg(feature = "sha3")]
fn test_hasher_256() {
let mut hasher = Sha3_256::default();
hasher.update(b"hello world");
Expand All @@ -103,6 +134,7 @@ mod tests {
}

#[test]
#[cfg(feature = "sha3")]
fn test_hasher_512() {
let mut hasher = Sha3_512::default();
hasher.update(b"hello world");
Expand All @@ -116,6 +148,7 @@ mod tests {
}

#[test]
#[cfg(feature = "sha2")]
fn roundtrip() {
let hash = Code::Sha2_256.digest(b"hello world");
let mut buf = [0u8; 35];
Expand All @@ -126,32 +159,37 @@ mod tests {
}

#[test]
#[cfg(feature = "sha2")]
fn test_truncate_down() {
let hash = Code::Sha2_256.digest(b"hello world");
let small = hash.truncate(20);
assert_eq!(small.size(), 20);
}

#[test]
#[cfg(feature = "sha2")]
fn test_truncate_up() {
let hash = Code::Sha2_256.digest(b"hello world");
let small = hash.truncate(100);
assert_eq!(small.size(), 32);
}

#[test]
#[cfg(feature = "sha2")]
fn test_resize_fits() {
let hash = Code::Sha2_256.digest(b"hello world");
let _: Multihash<32> = hash.resize().unwrap();
}

#[test]
#[cfg(feature = "sha2")]
fn test_resize_up() {
let hash = Code::Sha2_256.digest(b"hello world");
let _: Multihash<100> = hash.resize().unwrap();
}

#[test]
#[cfg(feature = "sha2")]
fn test_resize_truncate() {
let hash = Code::Sha2_256.digest(b"hello world");
hash.resize::<20>().unwrap_err();
Expand Down
4 changes: 2 additions & 2 deletions codetable/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::io::{Cursor, Write};

use multihash_codetable::{
Blake2b256, Blake2b512, Blake2s128, Blake2s256, Blake3_256, Identity256, Keccak224, Keccak256,
Keccak384, Keccak512, Sha1, Sha2_256, Sha2_512, Sha3_224, Sha3_256, Sha3_384, Sha3_512,
Strobe256, Strobe512,
Keccak384, Keccak512, Ripemd160, Ripemd256, Ripemd320, Sha1, Sha2_256, Sha2_512, Sha3_224,
Sha3_256, Sha3_384, Sha3_512, Strobe256, Strobe512,
};
use multihash_derive::{Hasher, MultihashDigest};

Expand Down
9 changes: 7 additions & 2 deletions derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ description = "Proc macro for deriving custom multihash tables."
license = "MIT"
repository = "https://github.com/multiformats/rust-multihash"

[features]
default = ["std"]
std = ["multihash/std", "core2/std"]

[dependencies]
multihash-derive-impl = { version = "0.1.0", path = "../derive-impl" }
multihash = { version = "0.18.0", path = "../" }
multihash = { version = "0.18.0", path = "../", default-features = false }
core2 = { version = "0.4.0", default-features = false }

[dev-dependencies]
trybuild = "1.0.80"
multihash-codetable = { path = "../codetable" }
multihash-codetable = { path = "../codetable", features = ["strobe"] }
Loading