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

Update to multihash 0.19 #140

Merged
merged 5 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ edition = "2021"
rust-version = "1.60"

[features]
default = ["std", "multihash/default"]
std = ["multihash/std", "unsigned-varint/std", "alloc", "multibase/std", "serde/std"]
default = ["std", "multihash/default", "multihash-codetable/default"]
std = ["multihash/std", "multihash-codetable/std", "unsigned-varint/std", "alloc", "multibase/std", "serde/std"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will add multihash-codetable by default. So just remove them from here.

I needed to check that myself and figured out that it's the same for the other optional dependencies as well. I guess we should fix that properly somehow. But for now at least not adding multihash-codetable is a good first step.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yep. The solution is ?/, which only sets it if present.

alloc = ["multibase", "multihash/alloc", "core2/alloc", "serde/alloc"]
arb = ["quickcheck", "rand", "multihash/arb", "multihash/multihash-impl", "multihash/sha2", "arbitrary"]
arb = ["quickcheck", "rand", "multihash/arb", "multihash-codetable", "arbitrary"]
scale-codec = ["parity-scale-codec", "multihash/scale-codec"]
serde-codec = ["alloc", "serde", "multihash/serde-codec", "serde_bytes"]

[dependencies]
multihash = { version = "0.18.0", default-features = false }
multihash = { version = "0.19.0", default-features = false }
multihash-codetable = { version = "0.1.0", default-features = false, features = ["digest", "sha2"], optional = true }
unsigned-varint = { version = "0.7.0", default-features = false }

multibase = { version = "0.9.1", optional = true, default-features = false }
Expand All @@ -33,5 +34,5 @@ arbitrary = { version = "1.1.0", optional = true }
core2 = { version = "0.4", default-features = false }

[dev-dependencies]
multihash-derive = { version = "0.9.0", default-features = false }
serde_json = "1.0.59"

2 changes: 1 addition & 1 deletion examples/readme.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cid::multihash::{Code, MultihashDigest};
use cid::Cid;
use multihash_codetable::{Code, MultihashDigest};
use std::convert::TryFrom;

const RAW: u64 = 0x55;
Expand Down
14 changes: 7 additions & 7 deletions src/arb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use std::convert::TryFrom;

use multihash::{Code, MultihashDigest, MultihashGeneric};
use multihash::Multihash;
use multihash_codetable::{Code, MultihashDigest};
use quickcheck::Gen;
use rand::{
distributions::{weighted::WeightedIndex, Distribution},
Expand Down Expand Up @@ -48,7 +49,7 @@ impl<const S: usize> quickcheck::Arbitrary for CidGeneric<S> {
_ => unreachable!(),
};

let hash: MultihashGeneric<S> = quickcheck::Arbitrary::arbitrary(g);
let hash: Multihash<S> = quickcheck::Arbitrary::arbitrary(g);
CidGeneric::new_v1(codec, hash)
}
}
Expand All @@ -57,7 +58,7 @@ impl<const S: usize> quickcheck::Arbitrary for CidGeneric<S> {
impl<'a, const S: usize> arbitrary::Arbitrary<'a> for CidGeneric<S> {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
if S >= 32 && u.ratio(1, 10)? {
let mh = MultihashGeneric::wrap(Code::Sha2_256.into(), u.bytes(32)?).unwrap();
let mh = Multihash::wrap(Code::Sha2_256.into(), u.bytes(32)?).unwrap();
return Ok(CidGeneric::new_v0(mh).expect("32 bytes is correct for v0"));
}

Expand Down Expand Up @@ -86,7 +87,7 @@ impl<'a, const S: usize> arbitrary::Arbitrary<'a> for CidGeneric<S> {
let v1 = size_hint::and_all(&[
<[u8; 2]>::size_hint(depth),
(0, Some(8)),
<MultihashGeneric<S> as arbitrary::Arbitrary>::size_hint(depth),
<Multihash<S> as arbitrary::Arbitrary>::size_hint(depth),
]);
if S >= 32 {
size_hint::and(<u8>::size_hint(depth), size_hint::or((32, Some(32)), v1))
Expand All @@ -100,7 +101,7 @@ impl<'a, const S: usize> arbitrary::Arbitrary<'a> for CidGeneric<S> {
mod tests {
use crate::CidGeneric;
use arbitrary::{Arbitrary, Unstructured};
use multihash::MultihashGeneric;
use multihash::Multihash;

#[test]
fn arbitrary() {
Expand All @@ -109,8 +110,7 @@ mod tests {
23, 32, 32, 23, 65, 98, 193, 108, 3,
]);
let c = <CidGeneric<16> as Arbitrary>::arbitrary(&mut u).unwrap();
let c2 =
CidGeneric::<16>::new_v1(22, MultihashGeneric::wrap(13, &[6, 7, 8, 9, 6]).unwrap());
let c2 = CidGeneric::<16>::new_v1(22, Multihash::wrap(13, &[6, 7, 8, 9, 6]).unwrap());
assert_eq!(c.hash(), c2.hash());
assert_eq!(c.codec(), c2.codec());
assert_eq!(c, c2)
Expand Down
4 changes: 2 additions & 2 deletions src/cid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::convert::TryFrom;
#[cfg(feature = "alloc")]
use multibase::{encode as base_encode, Base};

use multihash::MultihashGeneric as Multihash;
use multihash::Multihash;
use unsigned_varint::encode as varint_encode;

#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -228,7 +228,7 @@ impl<const S: usize> Cid<S> {
/// ```
/// use cid::Cid;
/// use multibase::Base;
/// use multihash::{Code, MultihashDigest};
/// use multihash_codetable::{Code, MultihashDigest};
///
/// const RAW: u64 = 0x55;
///
Expand Down
6 changes: 3 additions & 3 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::str::FromStr;

use cid::{Cid, CidGeneric, Error, Version};
use multibase::Base;
use multihash::{derive::Multihash, Code, MultihashDigest};
use multihash_codetable::{Code, MultihashDigest};

const RAW: u64 = 0x55;
const DAG_PB: u64 = 0x70;
Expand Down Expand Up @@ -174,10 +174,10 @@ fn a_function_that_takes_a_generic_cid<const S: usize>(cid: &CidGeneric<S>) -> S
// is using `Cid` instead of `Cid<SomeSize>`. The code will still work with other sizes.
#[test]
fn method_can_take_differently_sized_cids() {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Multihash)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, MultihashDigest)]
#[mh(alloc_size = 128)]
enum Code128 {
#[mh(code = 0x12, hasher = multihash::Sha2_256)]
#[mh(code = 0x12, hasher = multihash_codetable::Sha2_256)]
Sha2_256,
}

Expand Down
Loading