pubkey.c: Catch invalid arguments to `RSAPub' and `RSAPriv'.
[catacomb-python] / catacomb / __init__.py
index 6f80254..8dac0b4 100644 (file)
@@ -1,38 +1,35 @@
-# -*-python-*-
-#
-# $Id$
-#
-# Setup for Catacomb/Python bindings
-#
-# (c) 2004 Straylight/Edgeware
-#
-
-#----- Licensing notice -----------------------------------------------------
-#
-# This file is part of the Python interface to Catacomb.
-#
-# Catacomb/Python is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-# 
-# Catacomb/Python is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License
-# along with Catacomb/Python; if not, write to the Free Software Foundation,
-# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-#----- Imports --------------------------------------------------------------
+### -*-python-*-
+###
+### Setup for Catacomb/Python bindings
+###
+### (c) 2004 Straylight/Edgeware
+###
+
+###----- Licensing notice ---------------------------------------------------
+###
+### This file is part of the Python interface to Catacomb.
+###
+### Catacomb/Python is free software; you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation; either version 2 of the License, or
+### (at your option) any later version.
+###
+### Catacomb/Python is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with Catacomb/Python; if not, write to the Free Software Foundation,
+### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 import _base
 import types as _types
 from binascii import hexlify as _hexify, unhexlify as _unhexify
 from sys import argv as _argv
 
-#----- Basic stuff ----------------------------------------------------------
+###--------------------------------------------------------------------------
+### Basic stuff.
 
 ## For the benefit of the default keyreporter, we need the program na,e.
 _base._ego(_argv[0])
@@ -85,7 +82,8 @@ def _checkend(r):
     raise SyntaxError, 'junk at end of string'
   return x
 
-#----- Bytestrings ----------------------------------------------------------
+###--------------------------------------------------------------------------
+### Bytestrings.
 
 class _tmp:
   def fromhex(x):
@@ -98,7 +96,8 @@ class _tmp:
 _augment(ByteString, _tmp)
 bytes = ByteString.fromhex
 
-#----- Multiprecision integers and binary polynomials -----------------------
+###--------------------------------------------------------------------------
+### Multiprecision integers and binary polynomials.
 
 class _tmp:
   def negp(x): return x < 0
@@ -132,7 +131,8 @@ class _tmp:
   product = staticmethod(product)
 _augment(MPMul, _tmp)
 
-#----- Abstract fields ------------------------------------------------------
+###--------------------------------------------------------------------------
+### Abstract fields.
 
 class _tmp:
   def fromstring(str): return _checkend(Field.parse(str))
@@ -154,7 +154,8 @@ class _tmp:
   def __repr__(me): return '%s(%s)' % (repr(me.field), repr(me.value))
 _augment(FE, _tmp)
 
-#----- Elliptic curves ------------------------------------------------------
+###--------------------------------------------------------------------------
+### Elliptic curves.
 
 class _tmp:
   def __repr__(me):
@@ -193,7 +194,8 @@ class _tmp:
     return '(%s, %s)' % (me.x, me.y)
 _augment(ECPtCurve, _tmp)
 
-#----- Key sizes ------------------------------------------------------------
+###--------------------------------------------------------------------------
+### Key sizes.
 
 class _tmp:
   def __repr__(me): return 'KeySZAny(%d)' % me.default
@@ -223,7 +225,8 @@ class _tmp:
     return found
 _augment(KeySZSet, _tmp)
 
-#----- Abstract groups ------------------------------------------------------
+###--------------------------------------------------------------------------
+### Abstract groups.
 
 class _tmp:
   def __repr__(me):
@@ -249,7 +252,8 @@ class _tmp:
     return '%r(%r)' % (me.group, str(me))
 _augment(GE, _tmp)
 
-#----- RSA encoding techniques ----------------------------------------------
+###--------------------------------------------------------------------------
+### RSA encoding techniques.
 
 class PKCS1Crypt (object):
   def __init__(me, ep = '', rng = rand):
@@ -303,7 +307,7 @@ class _tmp:
       x = enc.decode(msg, me.pubop(sig), me.n.nbits)
       return x is None or x == msg
     except ValueError:
-      return False      
+      return False
 _augment(RSAPub, _tmp)
 
 class _tmp:
@@ -311,7 +315,8 @@ class _tmp:
   def sign(me, msg, enc): return me.privop(enc.encode(msg, me.n.nbits))
 _augment(RSAPriv, _tmp)
 
-#----- Built-in named curves and prime groups -------------------------------
+###--------------------------------------------------------------------------
+### Built-in named curves and prime groups.
 
 class _groupmap (object):
   def __init__(me, map, nth):
@@ -331,15 +336,26 @@ class _groupmap (object):
     raise TypeError, "immutable object"
   def __iter__(me):
     return iter(me.map)
+  def iterkeys(me):
+    return iter(me.map)
+  def itervalues(me):
+    for k in me:
+      yield me[k]
+  def iteritems(me):
+    for k in me:
+      yield k, me[k]
   def keys(me):
     return [k for k in me]
   def values(me):
     return [me[k] for k in me]
+  def items(me):
+    return [(k, me[k]) for k in me]
 eccurves = _groupmap(_base._eccurves, ECInfo._curven)
 primegroups = _groupmap(_base._pgroups, DHInfo._groupn)
 bingroups = _groupmap(_base._bingroups, BinDHInfo._groupn)
 
-#----- Prime number generation ----------------------------------------------
+###--------------------------------------------------------------------------
+### Prime number generation.
 
 class PrimeGenEventHandler (object):
   def pg_begin(me, ev):