]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
key_generator: make default key size be a constructor argument instead of a class...
authorZooko O'Whielacronx <zooko@zooko.com>
Tue, 22 Apr 2008 19:28:18 +0000 (12:28 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Tue, 22 Apr 2008 19:28:18 +0000 (12:28 -0700)
src/allmydata/key_generator.py
src/allmydata/scripts/keygen.py
src/allmydata/test/test_keygen.py

index fd9b096fa2a10d0c0d9f61081e4f523167fd06b5..97f7b13e42520044f473207027d601f47459bfbc 100644 (file)
@@ -14,15 +14,15 @@ from allmydata.interfaces import RIKeyGenerator
 class KeyGenerator(service.MultiService, foolscap.Referenceable):
     implements(RIKeyGenerator)
 
-    DEFAULT_KEY_SIZE = 2048
     pool_size = 16 # no. keys to keep on hand in the pool
     pool_refresh_delay = 6 # no. sec to wait after a fetch before generating new keys
     verbose = False
 
-    def __init__(self):
+    def __init__(self, default_key_size=2048):
         service.MultiService.__init__(self)
         self.keypool = []
         self.last_fetch = 0
+        self.default_key_size = default_key_size
 
     def startService(self):
         self.timer = reactor.callLater(0, self.maybe_refill_pool)
@@ -52,7 +52,7 @@ class KeyGenerator(service.MultiService, foolscap.Referenceable):
         if self.last_fetch + self.pool_refresh_delay < now:
             self.vlog('%s refilling pool' % (self,))
             while len(self.keypool) < self.pool_size:
-                self.keypool.append(self.gen_key(self.DEFAULT_KEY_SIZE))
+                self.keypool.append(self.gen_key(self.default_key_size))
         else:
             self.vlog('%s not refilling pool' % (self,))
             reactor.callLater(1, self.maybe_refill_pool)
@@ -65,7 +65,7 @@ class KeyGenerator(service.MultiService, foolscap.Referenceable):
 
     def remote_get_rsa_key_pair(self, key_size):
         self.vlog('%s remote_get_key' % (self,))
-        if key_size != self.DEFAULT_KEY_SIZE or not self.keypool:
+        if key_size != self.default_key_size or not self.keypool:
             key = self.gen_key(key_size)
             self.reset_timer()
             return key
@@ -76,12 +76,12 @@ class KeyGenerator(service.MultiService, foolscap.Referenceable):
 class KeyGeneratorService(service.MultiService):
     furl_file = 'key_generator.furl'
 
-    def __init__(self, basedir='.', display_furl=True):
+    def __init__(self, basedir='.', display_furl=True, default_key_size=2048):
         service.MultiService.__init__(self)
         self.basedir = basedir
         self.tub = foolscap.Tub(certFile=os.path.join(self.basedir, 'key_generator.pem'))
         self.tub.setServiceParent(self)
-        self.key_generator = KeyGenerator()
+        self.key_generator = KeyGenerator(default_key_size=default_key_size)
         self.key_generator.setServiceParent(self)
 
         portnum = self.get_portnum()
index f41e4956f5f06405c2aa98b93a7abf11826969be..c08422f9afe2848f33c4e2347a7cacb4bdca0e1c 100644 (file)
@@ -14,9 +14,8 @@ keygen_tac = """
 from allmydata import key_generator
 from twisted.application import service
 
-k = key_generator.KeyGeneratorService()
+k = key_generator.KeyGeneratorService(2048)
 #k.key_generator.verbose = False
-#k.key_generator.DEFAULT_KEY_SIZE = 2048
 #k.key_generator.pool_size = 16
 #k.key_generator.pool_refresh_delay = 6
 
index a6f354d6b0dc1d75762fd2ef48d5d9191694bbd6..27ed94db99068d1760f7005b5c0763e1b0813b7e 100644 (file)
@@ -40,11 +40,11 @@ class KeyGenService(unittest.TestCase, testutil.PollMixin):
             return junk
 
         #print 'starting key generator service'
-        kgs = key_generator.KeyGeneratorService(display_furl=False)
+        keysize = 522
+        kgs = key_generator.KeyGeneratorService(display_furl=False, default_key_size=keysize)
         kgs.key_generator.verbose = True
         kgs.setServiceParent(self.parent)
         kgs.key_generator.pool_size = 8
-        keysize = kgs.key_generator.DEFAULT_KEY_SIZE
 
         def keypool_full():
             return len(kgs.key_generator.keypool) == kgs.key_generator.pool_size