summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Toivonen <heikki@heikkitoivonen.net>2006-05-22 21:06:28 +0000
committerHeikki Toivonen <heikki@heikkitoivonen.net>2006-05-22 21:06:28 +0000
commit10976f21364e9888f837f614df279f9d7838e2ce (patch)
treed5f9ba3a10878dc4efad16051c539f84881306a0
parent4a1766fa91f8ebe271996ad7016fc4a6bc7007fa (diff)
downloadm2crypto-10976f21364e9888f837f614df279f9d7838e2ce.tar.gz
Add set_params function, last part of bug 5519.
git-svn-id: http://svn.osafoundation.org/m2crypto/trunk@442 2715db39-9adf-0310-9c64-84f055769b4b
-rw-r--r--M2Crypto/DSA.py19
-rw-r--r--tests/test_dsa.py9
2 files changed, 28 insertions, 0 deletions
diff --git a/M2Crypto/DSA.py b/M2Crypto/DSA.py
index c428cd5..cacee88 100644
--- a/M2Crypto/DSA.py
+++ b/M2Crypto/DSA.py
@@ -291,6 +291,25 @@ def gen_params(bits, callback=util.genparam_callback):
raise DSAError('problem generating DSA parameters')
return DSA(dsa, 1)
+def set_params(p, q, g):
+ """
+ Factory function that instantiates a DSA object with DSA
+ parameters.
+
+ @type p: str
+ @param p: value of p, a "byte string"
+ @type q: str
+ @param q: value of q, a "byte string"
+ @type g: str
+ @param g: value of g, a "byte string"
+ @rtype: DSA
+ @return: instance of DSA.
+ """
+ dsa = m2.dsa_new()
+ m2.dsa_set_p(dsa, p)
+ m2.dsa_set_q(dsa, q)
+ m2.dsa_set_g(dsa, g)
+ return DSA(dsa, 1)
def load_params(file, callback=util.passphrase_callback):
"""
diff --git a/tests/test_dsa.py b/tests/test_dsa.py
index c919122..25ef667 100644
--- a/tests/test_dsa.py
+++ b/tests/test_dsa.py
@@ -73,6 +73,15 @@ class DSATestCase(unittest.TestCase):
def check_genparam_setparam_genkey(self):
dsa = DSA.gen_params(256, self.callback)
assert len(dsa) == 512
+ p = dsa.p
+ q = dsa.q
+ g = dsa.g
+ dsa2 = DSA.set_params(p,q,g)
+ assert not dsa2.check_key()
+ dsa2.gen_key()
+ assert dsa2.check_key()
+ r,s = dsa2.sign(self.data)
+ assert dsa2.verify(self.data, r, s)
def suite():
return unittest.makeSuite(DSATestCase, 'check')