Skip to content

Commit 86c2088

Browse files
fix: don't depend on unnecessary multihash features (#77)
1 parent 454362a commit 86c2088

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# 0.18.0 [unreleased]
22

33
- Add `WebTransport` instance for `Multiaddr`. See [PR 70].
4+
- Disable all features of `multihash`. See [PR 77].
45

56
[PR 70]: https://github.com/multiformats/rust-multiaddr/pull/70
7+
[PR 77]: https://github.com/multiformats/rust-multiaddr/pull/77
68

79
# 0.17.0
810

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ arrayref = "0.3"
1818
byteorder = "1.3.1"
1919
data-encoding = "2.1"
2020
multibase = "0.9.1"
21-
multihash = { version = "0.18", default-features = false, features = ["std", "multihash-impl", "identity"] }
21+
multihash = { version = "0.18", default-features = false, features = ["std"] }
2222
percent-encoding = "2.1.0"
2323
serde = "1.0.70"
2424
static_assertions = "1.1"

src/protocol.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{Error, Result};
33
use arrayref::array_ref;
44
use byteorder::{BigEndian, ByteOrder, ReadBytesExt, WriteBytesExt};
55
use data_encoding::BASE32;
6-
use multihash::Multihash;
6+
use multihash::MultihashGeneric;
77
use std::{
88
borrow::Cow,
99
convert::From,
@@ -52,6 +52,13 @@ const WS_WITH_PATH: u32 = 4770; // Note: not standard
5252
const WSS: u32 = 478;
5353
const WSS_WITH_PATH: u32 = 4780; // Note: not standard
5454

55+
/// Type-alias for how multi-addresses use `Multihash`.
56+
///
57+
/// The `64` defines the allocation size for the digest within the `Multihash`.
58+
/// This allows us to use hashes such as SHA512.
59+
/// In case protocols like `/certhash` ever support hashes larger than that, we will need to update this size here (which will be a breaking change!).
60+
type Multihash = MultihashGeneric<64>;
61+
5562
const PATH_SEGMENT_ENCODE_SET: &percent_encoding::AsciiSet = &percent_encoding::CONTROLS
5663
.add(b'%')
5764
.add(b'/')

tests/lib.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
extern crate core;
2-
31
use data_encoding::HEXUPPER;
42
use multiaddr::*;
5-
use multihash::{Code, Multihash};
3+
use multihash::MultihashGeneric;
64
use quickcheck::{Arbitrary, Gen, QuickCheck};
75
use std::{
86
borrow::Cow,
@@ -145,14 +143,13 @@ impl Arbitrary for Proto {
145143
}
146144

147145
#[derive(Clone, Debug)]
148-
struct Mh(Multihash);
146+
struct Mh(MultihashGeneric<64>);
149147

150148
impl Arbitrary for Mh {
151149
fn arbitrary(g: &mut Gen) -> Self {
152150
let mut hash: [u8; 32] = [0; 32];
153151
hash.fill_with(|| u8::arbitrary(g));
154-
Mh(Multihash::wrap(Code::Identity.into(), &hash)
155-
.expect("The digest size is never too large"))
152+
Mh(MultihashGeneric::wrap(0x0, &hash).expect("The digest size is never too large"))
156153
}
157154
}
158155

@@ -180,8 +177,8 @@ fn ma_valid(source: &str, target: &str, protocols: Vec<Protocol<'_>>) {
180177
);
181178
}
182179

183-
fn multihash(s: &str) -> Multihash {
184-
Multihash::from_bytes(&multibase::Base::Base58Btc.decode(s).unwrap()).unwrap()
180+
fn multihash(s: &str) -> MultihashGeneric<64> {
181+
MultihashGeneric::from_bytes(&multibase::Base::Base58Btc.decode(s).unwrap()).unwrap()
185182
}
186183

187184
#[test]
@@ -374,7 +371,7 @@ fn construct_success() {
374371
Ip4(local),
375372
Udp(1234),
376373
WebRTC,
377-
Certhash(Multihash::from_bytes(&decoded).unwrap()),
374+
Certhash(MultihashGeneric::from_bytes(&decoded).unwrap()),
378375
],
379376
);
380377

@@ -393,7 +390,7 @@ fn construct_success() {
393390
Ip4(local),
394391
Udp(1234),
395392
WebTransport,
396-
Certhash(Multihash::from_bytes(&decoded).unwrap()),
393+
Certhash(MultihashGeneric::from_bytes(&decoded).unwrap()),
397394
],
398395
);
399396
}

0 commit comments

Comments
 (0)