From e852abcc2a481c681c06513cee0a9c260140b2d0 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Sun, 8 Sep 2019 23:00:14 -0700 Subject: [PATCH] refactor and make an interface to get the public key in an printable format --- ui/cli.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ui/cli.py b/ui/cli.py index bd94794..41b441e 100644 --- a/ui/cli.py +++ b/ui/cli.py @@ -221,6 +221,12 @@ class Persona(object): return self._identity + def get_pubkey(self): + '''Get a printable version of the public key. This is used + for importing into different programs, or for shared.''' + + return base58.b58encode_check(self._identity.pubkey) + def new_version(self, *args): '''Update the Persona's Identity object.''' @@ -502,7 +508,7 @@ def main(): persona = Persona.load(identfname) if options.printpub: - print base58.b58encode_check(persona.get_identity().pubkey) + print persona.get_pubkey() return persona.new_version(*addprops) @@ -717,6 +723,9 @@ class _TestCases(unittest.TestCase): idobj = persona.get_identity() self.assertIsInstance(idobj['pubkey'], str) + # that get_pubkey returns the correct thing + self.assertEqual(persona.get_pubkey(), base58.b58encode_check(idobj['pubkey'])) + # and that there is a signature self.assertIsInstance(idobj['sig'], str) @@ -917,7 +926,7 @@ class _TestCases(unittest.TestCase): # the correct key is printed self.assertEqual(stdout.getvalue(), - '%s\n' % base58.b58encode_check(pident.pubkey)) + '%s\n' % persona.get_pubkey()) # and looked up the correct file eu.assert_called_with('~/.medashare_identity.pasn1')