diff --git a/Cargo.lock b/Cargo.lock index 4093d49504b..ab510fc8ee2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6379,9 +6379,9 @@ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "uint" -version = "0.9.5" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +checksum = "909988d098b2f738727b161a106cfc7cab00c539c2687a8836f8e565976fb53e" dependencies = [ "byteorder", "crunchy", diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 295414f6ddd..63ce1e2f90c 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -26,7 +26,7 @@ libp2p-identity = { workspace = true, features = ["rand"] } rand = "0.8" sha2 = "0.10.8" smallvec = "1.13.2" -uint = "0.9" +uint = "0.10" futures-timer = "3.0.3" web-time = { workspace = true } serde = { version = "1.0", optional = true, features = ["derive"] } diff --git a/protocols/kad/src/kbucket.rs b/protocols/kad/src/kbucket.rs index 1c6d8857c9c..3f4b1281c3a 100644 --- a/protocols/kad/src/kbucket.rs +++ b/protocols/kad/src/kbucket.rs @@ -175,7 +175,7 @@ impl BucketIndex { let lower = usize::pow(2, rem); let upper = usize::pow(2, rem + 1); bytes[31 - quot] = rng.gen_range(lower..upper) as u8; - Distance(U256::from(bytes)) + Distance(U256::from_big_endian(bytes.as_slice())) } } @@ -650,7 +650,7 @@ mod tests { fn rand_distance() { fn prop(ix: u8) -> bool { let d = BucketIndex(ix as usize).rand_distance(&mut rand::thread_rng()); - let n = U256::from(<[u8; 32]>::from(d.0)); + let n = d.0; let b = U256::from(2); let e = U256::from(ix); let lower = b.pow(e); diff --git a/protocols/kad/src/kbucket/key.rs b/protocols/kad/src/kbucket/key.rs index 367dfa807d3..fb6362c6831 100644 --- a/protocols/kad/src/kbucket/key.rs +++ b/protocols/kad/src/kbucket/key.rs @@ -169,8 +169,8 @@ impl KeyBytes { where U: AsRef, { - let a = U256::from(self.0.as_slice()); - let b = U256::from(other.as_ref().0.as_slice()); + let a = U256::from_big_endian(self.0.as_slice()); + let b = U256::from_big_endian(other.as_ref().0.as_slice()); Distance(a ^ b) } @@ -180,8 +180,8 @@ impl KeyBytes { /// /// `self xor other = distance <==> other = self xor distance` pub fn for_distance(&self, d: Distance) -> KeyBytes { - let key_int = U256::from(self.0.as_slice()) ^ d.0; - KeyBytes(GenericArray::from(<[u8; 32]>::from(key_int))) + let key_int = U256::from_big_endian(self.0.as_slice()) ^ d.0; + KeyBytes(GenericArray::from(key_int.to_big_endian())) } }