From 1f40498fcfbb3e1c6fac117c01f1189a965e5f10 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 27 Apr 2021 22:57:45 +1000 Subject: [PATCH] Clippy nightly: disable owned cmp, stop comparing bool using assert_eq (#2073) * Disable clippy warnings about comparing a newly created struct In Sapling, we compare canonical JubJub bytes with a supplied byte array. Since we need to perform calculations to get it into canonical form, we need to create a newly owned object. * Clippy: use assert rather than assert_eq on a bool --- zebra-chain/src/sapling/keys.rs | 10 ++++++++++ zebra-network/src/isolated.rs | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/zebra-chain/src/sapling/keys.rs b/zebra-chain/src/sapling/keys.rs index 6461f560..4cf2c921 100644 --- a/zebra-chain/src/sapling/keys.rs +++ b/zebra-chain/src/sapling/keys.rs @@ -285,6 +285,8 @@ impl From for SpendAuthorizingKey { } impl PartialEq<[u8; 32]> for SpendAuthorizingKey { + // TODO: do we want to use constant-time comparison here? + #[allow(clippy::cmp_owned)] fn eq(&self, other: &[u8; 32]) -> bool { <[u8; 32]>::from(*self) == *other } @@ -326,6 +328,8 @@ impl From for ProofAuthorizingKey { } impl PartialEq<[u8; 32]> for ProofAuthorizingKey { + // TODO: do we want to use constant-time comparison here? + #[allow(clippy::cmp_owned)] fn eq(&self, other: &[u8; 32]) -> bool { <[u8; 32]>::from(*self) == *other } @@ -485,6 +489,8 @@ impl From for NullifierDerivingKey { } impl PartialEq<[u8; 32]> for NullifierDerivingKey { + // TODO: do we want to use constant-time comparison here? + #[allow(clippy::cmp_owned)] fn eq(&self, other: &[u8; 32]) -> bool { <[u8; 32]>::from(*self) == *other } @@ -776,6 +782,8 @@ impl From<(IncomingViewingKey, Diversifier)> for TransmissionKey { } impl PartialEq<[u8; 32]> for TransmissionKey { + // TODO: do we want to use constant-time comparison here? + #[allow(clippy::cmp_owned)] fn eq(&self, other: &[u8; 32]) -> bool { <[u8; 32]>::from(*self) == *other } @@ -898,6 +906,8 @@ impl From<&EphemeralPublicKey> for [u8; 32] { } impl PartialEq<[u8; 32]> for EphemeralPublicKey { + // TODO: do we want to use constant-time comparison here? + #[allow(clippy::cmp_owned)] fn eq(&self, other: &[u8; 32]) -> bool { <[u8; 32]>::from(self) == *other } diff --git a/zebra-network/src/isolated.rs b/zebra-network/src/isolated.rs index 759f45dc..18e8be2a 100644 --- a/zebra-network/src/isolated.rs +++ b/zebra-network/src/isolated.rs @@ -131,7 +131,7 @@ mod tests { ); assert_eq!(user_agent, ""); assert_eq!(start_height.0, 0); - assert_eq!(relay, false); + assert!(!relay); } else { panic!("handshake did not send version message"); }