From 034364c80b00f716b5941ac1a829e10209a74bd2 Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@allmydata.com>
Date: Wed, 1 Oct 2008 16:52:38 -0700
Subject: [PATCH] scripts/admin: split up generate_keypair code so that unit
 tests can use it more easily

---
 src/allmydata/scripts/admin.py | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

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):
-- 
2.45.2