Skip to content

Commit 6070a70

Browse files
committed
Implement PartialEq + Eq for NonIdentity and NonZeroScalar (RustCrypto#1834)
This is done by the fact that the underlying types implement these traits already.
1 parent 5028239 commit 6070a70

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

elliptic-curve/src/point/non_identity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{ops::MulByGenerator, CurveArithmetic, NonZeroScalar, Scalar};
1818
///
1919
/// In the context of ECC, it's useful for ensuring that certain arithmetic
2020
/// cannot result in the identity point.
21-
#[derive(Clone, Copy, Debug)]
21+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2222
pub struct NonIdentity<P> {
2323
point: P,
2424
}

elliptic-curve/src/scalar/nonzero.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ where
117117
}
118118
}
119119

120+
impl<C> Eq for NonZeroScalar<C> where C: CurveArithmetic {}
121+
120122
impl<C> From<NonZeroScalar<C>> for FieldBytes<C>
121123
where
122124
C: CurveArithmetic,
@@ -245,6 +247,15 @@ where
245247
}
246248
}
247249

250+
impl<C> PartialEq for NonZeroScalar<C>
251+
where
252+
C: CurveArithmetic,
253+
{
254+
fn eq(&self, other: &Self) -> bool {
255+
self.scalar.eq(&other.scalar)
256+
}
257+
}
258+
248259
/// Note: this is a non-zero reduction, as it's impl'd for [`NonZeroScalar`].
249260
impl<C, I> Reduce<I> for NonZeroScalar<C>
250261
where

0 commit comments

Comments
 (0)