From 2827f6a7e6820214ed4572e5dee8c1b09df8278c Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 11 May 2021 08:16:21 +1000 Subject: [PATCH] Orchard: disable clippy warnings about comparing a newly created struct (#2117) In Orchard, we compare canonical Pallas 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. --- zebra-chain/src/orchard/keys.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/zebra-chain/src/orchard/keys.rs b/zebra-chain/src/orchard/keys.rs index 6975217d..c873e5d4 100644 --- a/zebra-chain/src/orchard/keys.rs +++ b/zebra-chain/src/orchard/keys.rs @@ -233,6 +233,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 } @@ -271,12 +273,14 @@ impl From for SpendValidatingKey { } impl PartialEq for SpendValidatingKey { + #[allow(clippy::cmp_owned)] fn eq(&self, other: &Self) -> bool { <[u8; 32]>::from(self.0) == <[u8; 32]>::from(other.0) } } impl PartialEq<[u8; 32]> for SpendValidatingKey { + #[allow(clippy::cmp_owned)] fn eq(&self, other: &[u8; 32]) -> bool { <[u8; 32]>::from(self.0) == *other } @@ -338,6 +342,7 @@ impl From for NullifierDerivingKey { impl Eq for NullifierDerivingKey {} impl PartialEq<[u8; 32]> for NullifierDerivingKey { + #[allow(clippy::cmp_owned)] fn eq(&self, other: &[u8; 32]) -> bool { <[u8; 32]>::from(*self) == *other } @@ -826,6 +831,7 @@ impl From<(IncomingViewingKey, Diversifier)> for TransmissionKey { } impl PartialEq<[u8; 32]> for TransmissionKey { + #[allow(clippy::cmp_owned)] fn eq(&self, other: &[u8; 32]) -> bool { <[u8; 32]>::from(*self) == *other } @@ -866,6 +872,7 @@ impl From<&EphemeralPublicKey> for [u8; 32] { } impl PartialEq<[u8; 32]> for EphemeralPublicKey { + #[allow(clippy::cmp_owned)] fn eq(&self, other: &[u8; 32]) -> bool { <[u8; 32]>::from(self) == *other }