aboutsummaryrefslogtreecommitdiff
path: root/pyecsca/ec/point.py
blob: 05f25033e0a597962d3965a82ddc8f8a49c204d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from typing import Mapping

from .coordinates import CoordinateModel
from .mod import Mod


class Point(object):
    coordinate_model: CoordinateModel
    coords: Mapping[str, Mod]

    def __init__(self, model: CoordinateModel, **coords: Mod):
        if not set(model.variables) == set(coords.keys()):
            raise ValueError
        self.coordinate_model = model
        self.coords = coords

    def __eq__(self, other):
        # TODO: Somehow compare projective points. Via a map to an affinepoint?
        if type(other) is not Point:
            return False
        return self.coordinate_model == other.coordinate_model and self.coords == other.coords

    def __repr__(self):
        args = ", ".join([f"{key}={val}" for key, val in self.coords.items()])
        return f"Point([{args}] in {self.coordinate_model})"