generic_ec/point/
coords.rs1use crate::as_raw::{AsRaw, TryFromRaw};
2use crate::coords::*;
3use crate::core::coords as coords_core;
4use crate::core::*;
5
6use super::definition::Point;
7
8impl<E: Curve> HasAffineX<E> for Point<E>
9where
10 E: coords_core::HasAffineX,
11{
12 fn x(&self) -> Option<Coordinate<E>> {
13 E::x(self.as_raw()).map(Coordinate::new)
14 }
15}
16
17impl<E: Curve> HasAffineXAndParity<E> for Point<E>
18where
19 E: coords_core::HasAffineXAndParity,
20{
21 fn x_and_parity(&self) -> Option<(Coordinate<E>, Parity)> {
22 E::x_and_parity(self.as_raw()).map(|(x, p)| (Coordinate::new(x), p))
23 }
24
25 fn from_x_and_parity(x: &Coordinate<E>, y_parity: Parity) -> Option<Self> {
26 E::from_x_and_parity(x.as_array(), y_parity).and_then(Self::try_from_raw)
27 }
28}
29
30impl<E: Curve> HasAffineY<E> for Point<E>
31where
32 E: coords_core::HasAffineY,
33{
34 fn y(&self) -> Option<Coordinate<E>> {
35 E::y(self.as_raw()).map(Coordinate::new)
36 }
37}
38
39impl<E: Curve> HasAffineXY<E> for Point<E>
40where
41 E: coords_core::HasAffineXY,
42{
43 fn coords(&self) -> Option<Coordinates<E>> {
44 let (x, y) = E::x_and_y(self.as_raw())?;
45 Some(Coordinates {
46 x: Coordinate::new(x),
47 y: Coordinate::new(y),
48 })
49 }
50
51 fn from_coords(coords: &Coordinates<E>) -> Option<Self> {
52 E::from_x_and_y(coords.x.as_array(), coords.y.as_array()).and_then(Self::try_from_raw)
53 }
54}
55
56impl<E: Curve> AlwaysHasAffineY<E> for Point<E>
57where
58 E: coords_core::AlwaysHasAffineY,
59{
60 fn y(&self) -> Coordinate<E> {
61 Coordinate::new(E::y(self.as_raw()))
62 }
63}
64
65impl<E: Curve> AlwaysHasAffineYAndSign<E> for Point<E>
66where
67 E: coords_core::AlwaysHasAffineYAndSign,
68{
69 fn y_and_sign(&self) -> (Sign, Coordinate<E>) {
70 let (sign, coord) = E::y_and_sign(self.as_raw());
71 (sign, Coordinate::new(coord))
72 }
73
74 fn from_y_and_sign(x_sign: Sign, y: &Coordinate<E>) -> Option<Self> {
75 E::from_y_and_sign(x_sign, y.as_array()).and_then(Point::try_from_raw)
76 }
77}