Rename many .to_* methods to .into_*.

This commit is contained in:
Sean Bowe 2017-07-11 23:37:29 -06:00
parent ae69eb01b3
commit 647f83b53b
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
5 changed files with 49 additions and 49 deletions

View File

@ -140,7 +140,7 @@ macro_rules! curve_impl {
$prepared::from_affine(*self)
}
fn to_projective(&self) -> $projective {
fn into_projective(&self) -> $projective {
(*self).into()
}
}
@ -489,7 +489,7 @@ macro_rules! curve_impl {
*self = res;
}
fn to_affine(&self) -> $affine {
fn into_affine(&self) -> $affine {
(*self).into()
}
@ -980,15 +980,15 @@ pub mod g1 {
assert!(b.is_valid());
assert!(c.is_valid());
let mut tmp1 = a.to_projective();
tmp1.add_assign(&b.to_projective());
assert_eq!(tmp1.to_affine(), c);
assert_eq!(tmp1, c.to_projective());
let mut tmp1 = a.into_projective();
tmp1.add_assign(&b.into_projective());
assert_eq!(tmp1.into_affine(), c);
assert_eq!(tmp1, c.into_projective());
let mut tmp2 = a.to_projective();
let mut tmp2 = a.into_projective();
tmp2.add_assign_mixed(&b);
assert_eq!(tmp2.to_affine(), c);
assert_eq!(tmp2, c.to_projective());
assert_eq!(tmp2.into_affine(), c);
assert_eq!(tmp2, c.into_projective());
}
#[test]

View File

@ -9,7 +9,7 @@ fn test_vectors<G: CurveProjective, E: EncodedPoint<Affine=G::Affine>>(expected:
{
let mut expected = expected;
for _ in 0..1000 {
let e_affine = e.to_affine();
let e_affine = e.into_affine();
let encoded = E::from_affine(e_affine).unwrap();
v.extend_from_slice(encoded.as_ref());

View File

@ -124,7 +124,7 @@ pub trait CurveProjective: PartialEq +
fn mul_assign<S: Into<<Self::Scalar as PrimeField>::Repr>>(&mut self, other: S);
/// Converts this element into its affine representation.
fn to_affine(&self) -> Self::Affine;
fn into_affine(&self) -> Self::Affine;
/// Recommends a wNAF window table size given a scalar. Returns `None` if normal
/// scalar multiplication is encouraged. If `Some` is returned, it will be between
@ -178,17 +178,17 @@ pub trait CurveAffine: Copy +
fn prepare(&self) -> Self::Prepared;
/// Converts this element into its affine representation.
fn to_projective(&self) -> Self::Projective;
fn into_projective(&self) -> Self::Projective;
/// Converts this element into its compressed encoding, so long as it's not
/// the point at infinity.
fn to_compressed(&self) -> Result<Self::Compressed, ()> {
fn into_compressed(&self) -> Result<Self::Compressed, ()> {
<Self::Compressed as EncodedPoint>::from_affine(*self)
}
/// Converts this element into its uncompressed encoding, so long as it's not
/// the point at infinity.
fn to_uncompressed(&self) -> Result<Self::Uncompressed, ()> {
fn into_uncompressed(&self) -> Result<Self::Uncompressed, ()> {
<Self::Uncompressed as EncodedPoint>::from_affine(*self)
}
}

View File

@ -38,7 +38,7 @@ pub fn curve_tests<G: CurveProjective>()
let mut z2 = z;
z2.add_assign(&r);
z.add_assign_mixed(&r.to_affine());
z.add_assign_mixed(&r.into_affine());
assert_eq!(z, z2);
assert_eq!(z, r);
@ -47,8 +47,8 @@ pub fn curve_tests<G: CurveProjective>()
// Transformations
{
let a = G::rand(&mut rng);
let b = a.to_affine().to_projective();
let c = a.to_affine().to_projective().to_affine().to_projective();
let b = a.into_affine().into_projective();
let c = a.into_affine().into_projective().into_affine().into_projective();
assert_eq!(a, b);
assert_eq!(b, c);
}
@ -108,7 +108,7 @@ fn random_negation_tests<G: CurveProjective>() {
assert!(t3.is_zero());
let mut t4 = t1;
t4.add_assign_mixed(&t2.to_affine());
t4.add_assign_mixed(&t2.into_affine());
assert!(t4.is_zero());
t1.negate();
@ -136,7 +136,7 @@ fn random_doubling_tests<G: CurveProjective>() {
tmp2.add_assign(&b);
let mut tmp3 = a;
tmp3.add_assign_mixed(&b.to_affine());
tmp3.add_assign_mixed(&b.into_affine());
assert_eq!(tmp1, tmp2);
assert_eq!(tmp1, tmp3);
@ -149,8 +149,8 @@ fn random_multiplication_tests<G: CurveProjective>() {
for _ in 0..1000 {
let mut a = G::rand(&mut rng);
let mut b = G::rand(&mut rng);
let a_affine = a.to_affine();
let b_affine = b.to_affine();
let a_affine = a.into_affine();
let b_affine = b.into_affine();
let s = G::Scalar::rand(&mut rng);
@ -182,9 +182,9 @@ fn random_addition_tests<G: CurveProjective>() {
let a = G::rand(&mut rng);
let b = G::rand(&mut rng);
let c = G::rand(&mut rng);
let a_affine = a.to_affine();
let b_affine = b.to_affine();
let c_affine = c.to_affine();
let a_affine = a.into_affine();
let b_affine = b.into_affine();
let c_affine = c.into_affine();
// a + a should equal the doubling
{
@ -192,7 +192,7 @@ fn random_addition_tests<G: CurveProjective>() {
aplusa.add_assign(&a);
let mut aplusamixed = a;
aplusamixed.add_assign_mixed(&a.to_affine());
aplusamixed.add_assign_mixed(&a.into_affine());
let mut adouble = a;
adouble.double();
@ -221,17 +221,17 @@ fn random_addition_tests<G: CurveProjective>() {
// Mixed addition
// (a + b) + c
tmp[3] = a_affine.to_projective();
tmp[3] = a_affine.into_projective();
tmp[3].add_assign_mixed(&b_affine);
tmp[3].add_assign_mixed(&c_affine);
// a + (b + c)
tmp[4] = b_affine.to_projective();
tmp[4] = b_affine.into_projective();
tmp[4].add_assign_mixed(&c_affine);
tmp[4].add_assign_mixed(&a_affine);
// (a + c) + b
tmp[5] = a_affine.to_projective();
tmp[5] = a_affine.into_projective();
tmp[5].add_assign_mixed(&c_affine);
tmp[5].add_assign_mixed(&b_affine);
@ -239,7 +239,7 @@ fn random_addition_tests<G: CurveProjective>() {
for i in 0..6 {
for j in 0..6 {
assert_eq!(tmp[i], tmp[j]);
assert_eq!(tmp[i].to_affine(), tmp[j].to_affine());
assert_eq!(tmp[i].into_affine(), tmp[j].into_affine());
}
assert!(tmp[i] != a);
@ -258,8 +258,8 @@ fn random_transformation_tests<G: CurveProjective>() {
for _ in 0..1000 {
let g = G::rand(&mut rng);
let g_affine = g.to_affine();
let g_projective = g_affine.to_projective();
let g_affine = g.into_affine();
let g_projective = g_affine.into_projective();
assert_eq!(g, g_projective);
}
@ -279,10 +279,10 @@ fn random_transformation_tests<G: CurveProjective>() {
}
for _ in 0..5 {
let s = between.ind_sample(&mut rng);
v[s] = v[s].to_affine().to_projective();
v[s] = v[s].into_affine().into_projective();
}
let expected_v = v.iter().map(|v| v.to_affine().to_projective()).collect::<Vec<_>>();
let expected_v = v.iter().map(|v| v.into_affine().into_projective()).collect::<Vec<_>>();
G::batch_normalization(&mut v);
for i in &v {
@ -295,25 +295,25 @@ fn random_transformation_tests<G: CurveProjective>() {
fn random_encoding_tests<G: CurveAffine>()
{
assert!(G::zero().to_compressed().is_err());
assert!(G::zero().to_uncompressed().is_err());
assert!(G::zero().into_compressed().is_err());
assert!(G::zero().into_uncompressed().is_err());
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
for _ in 0..1000 {
let mut r = G::Projective::rand(&mut rng).to_affine();
let mut r = G::Projective::rand(&mut rng).into_affine();
let uncompressed = r.to_uncompressed().unwrap();
let uncompressed = r.into_uncompressed().unwrap();
let de_uncompressed = uncompressed.into_affine().unwrap();
assert_eq!(de_uncompressed, r);
let compressed = r.to_compressed().unwrap();
let compressed = r.into_compressed().unwrap();
let de_compressed = compressed.into_affine().unwrap();
assert_eq!(de_compressed, r);
r.negate();
let compressed = r.to_compressed().unwrap();
let compressed = r.into_compressed().unwrap();
let de_compressed = compressed.into_affine().unwrap();
assert_eq!(de_compressed, r);
}

View File

@ -10,10 +10,10 @@ pub fn engine_tests<E: Engine>()
let z1 = E::G1Affine::zero().prepare();
let z2 = E::G2Affine::zero().prepare();
let a = E::G1::rand(&mut rng).to_affine().prepare();
let b = E::G2::rand(&mut rng).to_affine().prepare();
let c = E::G1::rand(&mut rng).to_affine().prepare();
let d = E::G2::rand(&mut rng).to_affine().prepare();
let a = E::G1::rand(&mut rng).into_affine().prepare();
let b = E::G2::rand(&mut rng).into_affine().prepare();
let c = E::G1::rand(&mut rng).into_affine().prepare();
let d = E::G2::rand(&mut rng).into_affine().prepare();
assert_eq!(
E::Fqk::one(),
@ -50,8 +50,8 @@ fn random_miller_loop_tests<E: Engine>() {
let p2 = E::pairing(a, b);
let a = a.to_affine().prepare();
let b = b.to_affine().prepare();
let a = a.into_affine().prepare();
let b = b.into_affine().prepare();
let p1 = E::final_exponentiation(&E::miller_loop(&[(&a, &b)])).unwrap();
@ -71,10 +71,10 @@ fn random_miller_loop_tests<E: Engine>() {
let mut abcd = ab;
abcd.mul_assign(&cd);
let a = a.to_affine().prepare();
let b = b.to_affine().prepare();
let c = c.to_affine().prepare();
let d = d.to_affine().prepare();
let a = a.into_affine().prepare();
let b = b.into_affine().prepare();
let c = c.into_affine().prepare();
let d = d.into_affine().prepare();
let abcd_with_double_loop = E::final_exponentiation(
&E::miller_loop(&[(&a, &b), (&c, &d)])