use std::marker::PhantomData;
use std::ops::Deref;
use crate::elliptic::curves::traits::*;
use super::Point;
pub struct Generator<E: Curve> {
_ph: PhantomData<&'static E::Point>,
}
impl<E: Curve> Default for Generator<E> {
fn default() -> Self {
Self { _ph: PhantomData }
}
}
impl<E: Curve> Generator<E> {
pub fn to_point(self) -> Point<E> {
Point::from(self)
}
pub fn as_point(self) -> &'static Point<E> {
unsafe { Point::from_raw_ref_unchecked(self.as_raw()) }
}
pub fn as_raw(self) -> &'static E::Point {
E::Point::generator()
}
}
impl<E: Curve> Clone for Generator<E> {
fn clone(&self) -> Self {
Self { _ph: PhantomData }
}
}
impl<E: Curve> Copy for Generator<E> {}
impl<E: Curve> Deref for Generator<E> {
type Target = Point<E>;
fn deref(&self) -> &Point<E> {
self.as_point()
}
}