generic_ec/point/
definition.rs

1use zeroize::Zeroize;
2
3use crate::{as_raw::AsRaw, core::*};
4
5/// Torsion-free point on elliptic curve `E`
6///
7/// Any instance of `Point` is guaranteed to be on curve `E` and free of torsion component. Note that
8/// identity point (sometimes called _point at infinity_) is a valid point that can be obtained by calling
9/// [`Point::zero()`](Point::zero).
10///
11/// Point implements all necessary arithmetic operations: points addition, multiplication at scalar, etc.
12#[derive(Copy, Clone, Default, PartialEq, Eq)]
13pub struct Point<E: Curve>(E::Point);
14
15impl<E: Curve> Point<E> {
16    /// Constructs a point without checking whether it's valid
17    ///
18    /// Caller **must** guarantee validity of the point. Caller **must** provide a comment
19    /// justifying a call and proving that resulting point meets requirements:
20    ///
21    /// 1. Point is on curve
22    /// 2. Point is free of torsion component
23    pub(crate) fn from_raw_unchecked(point: E::Point) -> Self {
24        Point(point)
25    }
26}
27
28impl<E: Curve> AsRaw for Point<E> {
29    type Raw = E::Point;
30
31    #[inline]
32    fn as_raw(&self) -> &E::Point {
33        &self.0
34    }
35}
36
37impl<E: Curve> Zeroize for Point<E> {
38    fn zeroize(&mut self) {
39        self.0.zeroize()
40    }
41}