Skip to content

Implement PartialEq + Eq for NonIdentity and NonZeroScalar #1834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion elliptic-curve/src/point/non_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{CurveArithmetic, NonZeroScalar, Scalar};
///
/// In the context of ECC, it's useful for ensuring that certain arithmetic
/// cannot result in the identity point.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct NonIdentity<P> {
point: P,
}
Expand Down
11 changes: 11 additions & 0 deletions elliptic-curve/src/scalar/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ where
}
}

impl<C> Eq for NonZeroScalar<C> where C: CurveArithmetic {}

impl<C> From<NonZeroScalar<C>> for FieldBytes<C>
where
C: CurveArithmetic,
Expand Down Expand Up @@ -256,6 +258,15 @@ where
}
}

impl<C> PartialEq for NonZeroScalar<C>
where
C: CurveArithmetic,
{
fn eq(&self, other: &Self) -> bool {
self.scalar.eq(&other.scalar)
}
}

/// Note: this is a non-zero reduction, as it's impl'd for [`NonZeroScalar`].
impl<C, I> Reduce<I> for NonZeroScalar<C>
where
Expand Down