From: Brian Warner Date: Wed, 1 Oct 2008 23:52:38 +0000 (-0700) Subject: scripts/admin: split up generate_keypair code so that unit tests can use it more... X-Git-Url: https://git.rkrishnan.org/Site/Content/Exhibitors/frontends?a=commitdiff_plain;h=034364c80b00f716b5941ac1a829e10209a74bd2;p=tahoe-lafs%2Ftahoe-lafs.git scripts/admin: split up generate_keypair code so that unit tests can use it more easily --- diff --git a/src/allmydata/scripts/admin.py b/src/allmydata/scripts/admin.py index 119f8601..b05d6a43 100644 --- a/src/allmydata/scripts/admin.py +++ b/src/allmydata/scripts/admin.py @@ -14,14 +14,20 @@ base32-encoded text. """ return t -def generate_keypair(options): +def make_keypair(): from pycryptopp.publickey import ecdsa from allmydata.util import base32 - out = options.stdout privkey = ecdsa.generate(192) - print >>out, "private: priv-v0-%s" % base32.b2a(privkey.serialize()) + privkey_vs = "priv-v0-%s" % base32.b2a(privkey.serialize()) pubkey = privkey.get_verifying_key() - print >>out, "public: pub-v0-%s" % base32.b2a(pubkey.serialize()) + pubkey_vs = "pub-v0-%s" % base32.b2a(pubkey.serialize()) + return privkey_vs, pubkey_vs + +def print_keypair(options): + out = options.stdout + privkey_vs, pubkey_vs = make_keypair() + print >>out, "private:", privkey_vs + print >>out, "public:", pubkey_vs class AdminCommand(usage.Options): subCommands = [ @@ -46,7 +52,7 @@ each subcommand. return t subDispatch = { - "generate-keypair": generate_keypair, + "generate-keypair": print_keypair, } def do_admin(options):