generic_ec/non_zero/
coords.rs

1use crate::coords::{
2    AlwaysHasAffineX, AlwaysHasAffineXY, AlwaysHasAffineY, HasAffineX, HasAffineXY, HasAffineY,
3};
4use crate::{Curve, Point};
5
6use super::definition::NonZero;
7
8impl<E: Curve> AlwaysHasAffineX<E> for NonZero<Point<E>>
9where
10    Point<E>: HasAffineX<E>,
11{
12    fn x(&self) -> crate::coords::Coordinate<E> {
13        // The only point that may not have coords for some curves is point at infinity (or
14        // identity point). Since we know it's non-zero, it must have coordinates
15        #![allow(clippy::expect_used)]
16        HasAffineX::x(&**self).expect("non-zero point always has coordinates")
17    }
18}
19
20impl<E: Curve> AlwaysHasAffineY<E> for NonZero<Point<E>>
21where
22    Point<E>: HasAffineY<E>,
23{
24    fn y(&self) -> crate::coords::Coordinate<E> {
25        // The only point that may not have coords for some curves is point at infinity (or
26        // identity point). Since we know it's non-zero, it must have coordinates
27        #![allow(clippy::expect_used)]
28        HasAffineY::y(&**self).expect("non-zero point always has coordinates")
29    }
30}
31
32impl<E: Curve> AlwaysHasAffineXY<E> for NonZero<Point<E>>
33where
34    Point<E>: HasAffineXY<E>,
35{
36    fn from_coords(coords: &crate::coords::Coordinates<E>) -> Option<Self> {
37        <Point<E> as HasAffineXY<E>>::from_coords(coords).and_then(NonZero::from_point)
38    }
39}