math/mpgen: Fix bugs in slot handling.
[catacomb] / math / mpgen
index 683970f..9a66af1 100644 (file)
@@ -383,8 +383,8 @@ class BaseSlot (object):
   def __init__(me, name, headline = False, omitp = None, allowp = None):
     me.name = name
     me.headline = headline
-    me._omitp = None
-    me._allowp = None
+    me._omitp = omitp
+    me._allowp = allowp
   def set(me, st, value):
     if me._allowp and not me._allowp(st, value):
       raise Exception, "slot `%s' not allowed here" % me.name
@@ -408,6 +408,7 @@ class EnumSlot (BaseSlot):
 
 class MPSlot (BaseSlot):
   def setup(me, st):
+    super(MPSlot, me).setup(st)
     v = st.d.get(me)
     if v not in st.mpmap:
       write_limbs('v%d' % st.nextmp, v)
@@ -435,13 +436,16 @@ class EllipticCurveTable (GroupTable):
   data_t = 'ecdata'
   entry_t = 'ecentry'
   tabname = 'ectab'
-  slots = [EnumSlot('type', 'FTAG',
-                    ['prime', 'niceprime', 'binpoly', 'binnorm'],
-                    headline = True),
+  _typeslot = EnumSlot('type', 'FTAG',
+                       ['prime', 'niceprime', 'binpoly', 'binnorm'],
+                       headline = True)
+  slots = [_typeslot,
            MPSlot('p'),
            MPSlot('beta',
-                  allowp = lambda st, _: st.d['type'] == 'binnorm',
-                  omitp = lambda st: st.d['type'] != 'binnorm'),
+                  allowp = lambda st, _:
+                    st.d[EllipticCurveTable._typeslot] == 'binnorm',
+                  omitp = lambda st:
+                    st.d[EllipticCurveTable._typeslot] != 'binnorm'),
            MPSlot('a'), MPSlot('b'), MPSlot('r'), MPSlot('h'),
            MPSlot('gx'), MPSlot('gy')]