Skip to content
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

Derives and borrows #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub trait CurveProjective:

/// Normalizes a slice of projective elements so that
/// conversion to affine is cheap.
fn batch_normalization(v: &mut [Self]);
fn batch_normalization<S: ::std::borrow::BorrowMut<Self>>(v: &mut [S]);
Copy link
Member

@str4d str4d Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change would now apply to Curve::batch_normalize, and would look something like:

use core::borrow::{Borrow, BorrowMut};
...
fn batch_normalize<P: Borrow<Self>, Q: BorrowMut<Self::AffineRepr>>(p: &[P], q: &mut [Q]) {

However, when I tried this locally, I ran into issues with &P not implementing Curve, that I wasn't immediately able to figure out how to resolve. Perhaps the P: Borrow<Self> is unnecessary flexibility?


/// Checks if the point is already "normalized" so that
/// cheap affine conversion is possible.
Expand Down Expand Up @@ -121,7 +121,8 @@ pub trait CurveAffine:

/// An encoded elliptic curve point, which should essentially wrap a `[u8; N]`.
pub trait EncodedPoint:
Sized + Send + Sync + AsRef<[u8]> + AsMut<[u8]> + Clone + Copy + 'static
Sized + Send + Sync + AsRef<[u8]> + AsMut<[u8]> + Clone + Copy
+ PartialOrd + Ord + PartialEq + Eq + ::std::hash::Hash + 'static
Comment on lines +124 to +125
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These bounds should now be applied to GroupEncoding::Repr and UncompressedEncoding::Repr. Also add use core::hash::Hash at the top of the file instead of the explicit form here.

{
type Affine: CurveAffine;

Expand Down