ec.c: Dispatch to `ecptxl_3' whether or not we have a curve.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 24 Nov 2019 22:42:10 +0000 (22:42 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 25 Nov 2019 17:51:32 +0000 (17:51 +0000)
The `ecptxl_3' function has a better error message in the case where
there is no curve.  Indeed, `want sequence of two or three items' is
downright unfair in the case where you did in fact supply a sequence of
three items, and the real problem is that you're trying to construct a
curveless point.

ec.c
t/t-ec.py

diff --git a/ec.c b/ec.c
index 7a6ed95..6831552 100644 (file)
--- a/ec.c
+++ b/ec.c
@@ -533,7 +533,7 @@ static int ecptxl_1(ec_curve *c, ec *p, PyObject *x)
   } else if (PySequence_Check(x)) {
     t = x; x = 0;
     n = PySequence_Size(t); if (n < 0) goto end;
-    if (n != 2 && (n != 3 || !c))
+    if (n != 2 && n != 3)
       TYERR("want sequence of two or three items");
     if ((x = PySequence_GetItem(t, 0)) == 0 ||
        (y = PySequence_GetItem(t, 1)) == 0 ||
index 02ae4d1..f11da7d 100644 (file)
--- a/t/t-ec.py
+++ b/t/t-ec.py
@@ -60,7 +60,7 @@ class TestCurvelessPoints (U.TestCase):
     me.assertRaises(ValueError, C.ECPt, "12345,")
     me.assertRaises(ValueError, C.ECPt, "12345, xyzzy")
     me.assertRaises(ValueError, C.ECPt, "12345, 67890!??")
-    me.assertRaises(TypeError, C.ECPt, (1, 2, 3))
+    me.assertRaises(ValueError, C.ECPt, (1, 2, 3))
     me.assertRaises(TypeError, C.ECPt, 1, 2, 3)
     me.assertRaises(TypeError, C.ECPt, 1234)
     me.assertRaises(TypeError, C.ECPt, object())