Skip to content

Commit 658be9d

Browse files
authored
Merge pull request #45 from multiformats/dependabot/cargo/rand-0.8.4
Update rand requirement from 0.7.2 to 0.8.4
2 parents 1e263d1 + dc92286 commit 658be9d

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
- Update to multihash v0.14.0 (see [PR 44]).
44

5+
- Update to rand v0.8.4 (see [PR 45]).
6+
57
[PR 44]: https://github.com/multiformats/rust-multiaddr/pull/44
8+
[PR 45]: https://github.com/multiformats/rust-multiaddr/pull/45
69

710
# 0.12.0 [2021-05-26]
811

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ url = { version = "2.1.0", optional = true, default-features = false }
2727
[dev-dependencies]
2828
bincode = "1"
2929
quickcheck = "0.9.0"
30-
rand = "0.7.2"
30+
rand = "0.8.4"
3131
serde_json = "1.0"

tests/lib.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ use data_encoding::HEXUPPER;
22
use multihash::Multihash;
33
use multiaddr::*;
44
use quickcheck::{Arbitrary, Gen, QuickCheck};
5-
use rand::Rng;
65
use std::{
76
borrow::Cow,
8-
convert::TryFrom,
9-
iter::FromIterator,
7+
convert::{TryFrom, TryInto},
8+
iter::{FromIterator, self},
109
net::{Ipv4Addr, Ipv6Addr},
1110
str::FromStr
1211
};
@@ -87,8 +86,8 @@ struct Proto(Protocol<'static>);
8786
impl Arbitrary for Proto {
8887
fn arbitrary<G: Gen>(g: &mut G) -> Self {
8988
use Protocol::*;
90-
match g.gen_range(0, 25) { // TODO: Add Protocol::Quic
91-
0 => Proto(Dccp(g.gen())),
89+
match u8::arbitrary(g) % 25 { // TODO: Add Protocol::Quic
90+
0 => Proto(Dccp(Arbitrary::arbitrary(g))),
9291
1 => Proto(Dns(Cow::Owned(SubString::arbitrary(g).0))),
9392
2 => Proto(Dns4(Cow::Owned(SubString::arbitrary(g).0))),
9493
3 => Proto(Dns6(Cow::Owned(SubString::arbitrary(g).0))),
@@ -99,28 +98,35 @@ impl Arbitrary for Proto {
9998
8 => Proto(P2pWebRtcDirect),
10099
9 => Proto(P2pWebRtcStar),
101100
10 => Proto(P2pWebSocketStar),
102-
11 => Proto(Memory(g.gen())),
101+
11 => Proto(Memory(Arbitrary::arbitrary(g))),
103102
// TODO: impl Arbitrary for Multihash:
104103
12 => Proto(P2p(multihash("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"))),
105104
13 => Proto(P2pCircuit),
106105
14 => Proto(Quic),
107-
15 => Proto(Sctp(g.gen())),
108-
16 => Proto(Tcp(g.gen())),
109-
17 => Proto(Udp(g.gen())),
106+
15 => Proto(Sctp(Arbitrary::arbitrary(g))),
107+
16 => Proto(Tcp(Arbitrary::arbitrary(g))),
108+
17 => Proto(Udp(Arbitrary::arbitrary(g))),
110109
18 => Proto(Udt),
111110
19 => Proto(Unix(Cow::Owned(SubString::arbitrary(g).0))),
112111
20 => Proto(Utp),
113112
21 => Proto(Ws("/".into())),
114113
22 => Proto(Wss("/".into())),
115114
23 => {
116-
let mut a = [0; 10];
117-
g.fill(&mut a);
118-
Proto(Onion(Cow::Owned(a), g.gen_range(1, std::u16::MAX)))
115+
116+
let a = iter::repeat_with(|| u8::arbitrary(g))
117+
.take(10)
118+
.collect::<Vec<_>>()
119+
.try_into()
120+
.unwrap();
121+
Proto(Onion(Cow::Owned(a), std::cmp::max(1, u16::arbitrary(g))))
119122
},
120123
24 => {
121-
let mut a = [0; 35];
122-
g.fill_bytes(&mut a);
123-
Proto(Onion3((a, g.gen_range(1, std::u16::MAX)).into()))
124+
let a: [u8;35] = iter::repeat_with(|| u8::arbitrary(g))
125+
.take(35)
126+
.collect::<Vec<_>>()
127+
.try_into()
128+
.unwrap();
129+
Proto(Onion3((a, std::cmp::max(1, u16::arbitrary(g))).into()))
124130
},
125131
_ => panic!("outside range")
126132
}

0 commit comments

Comments
 (0)