ec.c, catacomb/__init__.py: Return tail from `parse'; provide `fromstring'.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 24 Nov 2019 22:50:56 +0000 (22:50 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 25 Nov 2019 17:51:32 +0000 (17:51 +0000)
`ECCurve.parse' was inconsistent with the established nomenclature.
Generally, `parse' reads a prefix of some given string, returning the
denoted value and the unprocessed remainder of the input string;
`fromstring' does the same, except that it returns only the value, and
raises an exception if the remainder of the string is not only
whitespace.

Fix `ECCurve.parse' (which unfortunately is an incompatible change), and
add missing `fromstring' methods to `ECCurve' and `ECInfo'.

catacomb/__init__.py
ec.c
t/t-ec.py

index 725f6d2..08ec3d7 100644 (file)
@@ -444,6 +444,8 @@ class _tmp:
       pp.pretty(me.a); pp.text(','); pp.breakable()
       pp.pretty(me.b)
     pp.end_group(ind, ')')
+  def fromstring(str): return _checkend(ECCurve.parse(str))
+  fromstring = staticmethod(fromstring)
   def frombuf(me, s):
     return ecpt.frombuf(me, s)
   def fromraw(me, s):
@@ -508,6 +510,8 @@ class _tmp:
     h ^=   hash(me.curve)
     h ^= 2*hash(me.G) & 0xffffffff
     return h
+  def fromstring(str): return _checkend(ECInfo.parse(str))
+  fromstring = staticmethod(fromstring)
   def group(me):
     return ECGroup(me)
 _augment(ECInfo, _tmp)
diff --git a/ec.c b/ec.c
index 95b59ef..f5a3aca 100644 (file)
--- a/ec.c
+++ b/ec.c
@@ -986,7 +986,7 @@ static PyObject *ecmeth_parse(PyObject *me, PyObject *arg)
   if (!PyArg_ParseTuple(arg, "s:parse", &p)) goto end;
   qd.p = p; qd.e = 0;
   if ((c = ec_curveparse(&qd)) == 0) VALERR(qd.e);
-  rc = eccurve_pywrap(0, c);
+  rc = Py_BuildValue("(Ns)", eccurve_pywrap(0, c), qd.p);
 end:
   return (rc);
 }
index 01b5f27..d854216 100644 (file)
--- a/t/t-ec.py
+++ b/t/t-ec.py
@@ -251,7 +251,7 @@ class TestCurves (T.GenericTestMixin):
 
   def test_tinycurves(me):
     me._test_curve(C.ECInfo(E, 2*P, 13, 2), checkfail = True)
-    ei, _ = C.ECInfo.parse("binpoly: 0x13; bin: 0x01, 0x08; 0x02, 0x0c: 5*4")
+    ei = C.ECInfo.fromstring("binpoly: 0x13; bin: 0x01, 0x08; 0x02, 0x0c: 5*4")
     me._test_curve(ei, checkfail = True)
 
 TestCurves.generate_testcases((name, C.eccurves[name]) for name in