From b1ddcca69421a27a09b2f5a5531f02936192736a Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sun, 24 Nov 2019 22:46:33 +0000 Subject: [PATCH] ec.c: Accept and discard parentheses around a point when parsing. The `str' function returns parentheses around the coordinates, so it seems unfair to reject parentheses on input. --- ec.c | 8 ++++++++ t/t-ec.py | 2 ++ 2 files changed, 10 insertions(+) diff --git a/ec.c b/ec.c index 770e71d..094bd00 100644 --- a/ec.c +++ b/ec.c @@ -333,11 +333,15 @@ static PyObject *epmeth_parse(PyObject *me, PyObject *arg) char *p; qd_parse qd; PyObject *rc = 0; + int paren; ec pp = EC_INIT; if (!PyArg_ParseTuple(arg, "s:parse", &p)) goto end; qd.p = p; qd.e = 0; + qd_skipspc(&qd); paren = qd_delim(&qd, '('); if (!ec_ptparse(&qd, &pp)) VALERR(qd.e); + qd_skipspc(&qd); if (paren && !qd_delim(&qd, ')')) + { EC_DESTROY(&pp); VALERR("missing `)'"); } rc = Py_BuildValue("(Ns)", ecpt_pywrapout(me, &pp), qd.p); end: return (rc); @@ -513,6 +517,7 @@ static int ecptxl_1(ec_curve *c, ec *p, PyObject *x) mp *xx = 0; Py_ssize_t n; qd_parse qd; + int paren; Py_XINCREF(x); if (!x || x == Py_None) @@ -522,7 +527,10 @@ static int ecptxl_1(ec_curve *c, ec *p, PyObject *x) goto fix; } else if (TEXT_CHECK(x)) { qd.p = TEXT_PTR(x); qd.e = 0; + qd_skipspc(&qd); paren = qd_delim(&qd, '('); if (!ec_ptparse(&qd, p)) VALERR(qd.e); + qd_skipspc(&qd); if (paren && !qd_delim(&qd, ')')) + { EC_DESTROY(p); VALERR("missing `)'"); } qd_skipspc(&qd); if (!qd_eofp(&qd)) VALERR("junk at eof"); goto fix; } else if (c && (xx = tomp(x)) != 0) { diff --git a/t/t-ec.py b/t/t-ec.py index f11da7d..01b5f27 100644 --- a/t/t-ec.py +++ b/t/t-ec.py @@ -93,7 +93,9 @@ class TestCurvelessPoints (U.TestCase): me.assertRaises(ValueError, C.ECPt.frombuf, C.bytes("0001fe000201")) ## String conversion and parsing. + me.assertEqual(str(P), "(254, 291)") me.assertEqual(C.ECPt.parse("254, 291)"), (P, ")")) + me.assertEqual(C.ECPt.parse("(254, 291)"), (P, "")) me.assertRaises(ValueError, C.ECPt.parse, "(254, 291") ###-------------------------------------------------------------------------- -- 2.11.0