Skip to content

Commit bb8c9aa

Browse files
authored
Merge pull request ojarva#85 from jbazik/add-key-accessor
Add key property to retrieve base64 key text. Also test for same.
2 parents fbf9c7a + 0e8ee73 commit bb8c9aa

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

sshpubkeys/keys.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ def reset(self):
198198
for field in self.FIELDS:
199199
setattr(self, field, None)
200200

201+
@property
202+
def key(self):
203+
"""Base64 encoded key"""
204+
return base64.b64encode(self._decoded_key)
205+
201206
def hash(self):
202207
"""Calculate md5 fingerprint.
203208

tests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ def check_fail(self, pubkey, expected_error, **kwargs):
5757
ssh_key = SSHKey(pubkey, **kwargs)
5858
self.assertRaises(expected_error, ssh_key.parse)
5959

60+
def test_key_property(self):
61+
ssh = SSHKey(DEFAULT_KEY)
62+
self.assertEqual(ssh.key, DEFAULT_KEY.split()[1].encode())
63+
6064

6165
class TestOptions(unittest.TestCase):
6266
def check_valid_option(self, option, parsed_option):

0 commit comments

Comments
 (0)