summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMichal Kuffa <michal@bynder.com>2017-07-28 14:24:15 +0200
committerMichal Kuffa <michal@bynder.com>2017-07-28 14:24:15 +0200
commite114b0d3f57842b3ddcf0bcc5d19e9f24399cace (patch)
treeb56bc7f8d38f53eae60fec8687202de1e85a8b88
parent08f503740182608570ac87661225fe2e11914d8f (diff)
Add file_obj handling to the Ed25519Key constructor
-rw-r--r--paramiko/ed25519key.py9
-rw-r--r--tests/test_pkey.py6
2 files changed, 13 insertions, 2 deletions
diff --git a/paramiko/ed25519key.py b/paramiko/ed25519key.py
index a50d68bc..0fbc2f67 100644
--- a/paramiko/ed25519key.py
+++ b/paramiko/ed25519key.py
@@ -45,7 +45,8 @@ def unpad(data):
class Ed25519Key(PKey):
- def __init__(self, msg=None, data=None, filename=None, password=None):
+ def __init__(self, msg=None, data=None, filename=None, password=None,
+ file_obj=None):
verifying_key = signing_key = None
if msg is None and data is not None:
msg = Message(data)
@@ -56,7 +57,11 @@ class Ed25519Key(PKey):
elif filename is not None:
with open(filename, "r") as f:
data = self._read_private_key("OPENSSH", f)
- signing_key = self._parse_signing_key_data(data, password)
+ elif file_obj is not None:
+ data = self._read_private_key("OPENSSH", file_obj)
+
+ if filename or file_obj:
+ signing_key = self._parse_signing_key_data(data, password)
if signing_key is None and verifying_key is None:
raise ValueError("need a key")
diff --git a/tests/test_pkey.py b/tests/test_pkey.py
index 9bb3c44c..89a3f74a 100644
--- a/tests/test_pkey.py
+++ b/tests/test_pkey.py
@@ -466,6 +466,12 @@ class KeyTest(unittest.TestCase):
self.assertTrue(not pub.can_sign())
self.assertEqual(key, pub)
+ def test_ed25519_load_from_file_obj(self):
+ with open(test_path('test_ed25519.key')) as pkey_fileobj:
+ key = Ed25519Key.from_private_key(pkey_fileobj)
+ self.assertEqual(key, key)
+ self.assertTrue(key.can_sign())
+
def test_keyfile_is_actually_encrypted(self):
# Read an existing encrypted private key
file_ = test_path('test_rsa_password.key')