Skip to content

Commit 8125ca2

Browse files
committed
test coverage for CurveEdTw() __str__
1 parent c5b7c7a commit 8125ca2

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/ecdsa/ellipticcurve.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,17 @@ def cofactor(self):
225225
return self.__h
226226

227227
def __str__(self):
228-
return "CurveEdTw(p={0}, a={1}, d={2}, h={3})".format(
228+
if self.__h is not None:
229+
return "CurveEdTw(p={0}, a={1}, d={2}, h={3})".format(
230+
self.__p,
231+
self.__a,
232+
self.__d,
233+
self.__h,
234+
)
235+
return "CurveEdTw(p={0}, a={1}, d={2})".format(
229236
self.__p,
230237
self.__a,
231238
self.__d,
232-
self.__h,
233239
)
234240

235241

src/ecdsa/test_ellipticcurve.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
except ImportError: # pragma: no cover
1515
HC_PRESENT = False
1616
from .numbertheory import inverse_mod
17-
from .ellipticcurve import CurveFp, INFINITY, Point
17+
from .ellipticcurve import CurveFp, INFINITY, Point, CurveEdTw
1818

1919

2020
HYP_SETTINGS = {}
@@ -105,6 +105,19 @@ def test___str___with_cofactor(self):
105105
self.assertEqual(str(c), "CurveFp(p=23, a=1, b=1, h=4)")
106106

107107

108+
class TestCurveEdTw(unittest.TestCase):
109+
@classmethod
110+
def setUpClass(cls):
111+
cls.c_23 = CurveEdTw(23, 1, 1)
112+
113+
def test___str__(self):
114+
self.assertEqual(str(self.c_23), "CurveEdTw(p=23, a=1, d=1)")
115+
116+
def test___str___with_cofactor(self):
117+
c = CurveEdTw(23, 1, 1, 4)
118+
self.assertEqual(str(c), "CurveEdTw(p=23, a=1, d=1, h=4)")
119+
120+
108121
class TestPoint(unittest.TestCase):
109122
@classmethod
110123
def setUpClass(cls):

0 commit comments

Comments
 (0)