aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--pyecsca/ec/point.py13
-rw-r--r--test/ec/test_point.py11
2 files changed, 24 insertions, 0 deletions
diff --git a/pyecsca/ec/point.py b/pyecsca/ec/point.py
index c7f99db..c4da538 100644
--- a/pyecsca/ec/point.py
+++ b/pyecsca/ec/point.py
@@ -182,6 +182,13 @@ class Point:
"""Test whether this point is equal to `other` irrespective of the coordinate model (in the affine sense)."""
return self.equals_affine(other)
+ def __iter__(self):
+ for k in sorted(self.coords.keys()):
+ yield self.coords[k]
+
+ def __len__(self):
+ return len(self.coords)
+
def __bytes__(self):
res = b"\x04"
for k in sorted(self.coords.keys()):
@@ -231,6 +238,12 @@ class InfinityPoint(Point):
def equals(self, other: "Point") -> bool:
return self == other
+ def __iter__(self):
+ pass
+
+ def __len__(self):
+ return 0
+
def __bytes__(self):
return b"\x00"
diff --git a/test/ec/test_point.py b/test/ec/test_point.py
index 51907ec..b2096be 100644
--- a/test/ec/test_point.py
+++ b/test/ec/test_point.py
@@ -131,3 +131,14 @@ class PointTests(TestCase):
b"\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02",
)
self.assertEqual(bytes(InfinityPoint(self.coords)), b"\x00")
+
+ def test_iter(self):
+ pt = Point(
+ self.coords,
+ X=Mod(0x4, self.secp128r1.curve.prime),
+ Y=Mod(0x6, self.secp128r1.curve.prime),
+ Z=Mod(2, self.secp128r1.curve.prime),
+ )
+ t = tuple(pt)
+ self.assertEqual(len(t), 3)
+ self.assertEqual(len(pt), 3)