summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPierce Lopez <pierce.lopez@gmail.com>2017-06-13 13:37:14 -0400
committerPierce Lopez <pierce.lopez@gmail.com>2017-06-13 13:37:14 -0400
commit1d8bb422bf8cf79b8a148e48c4c9b57966a43542 (patch)
tree45a2653b4511f67c780c715820486919a681453a
parent517685caaed0326c37d5de1a24ac257ddd296833 (diff)
implement __hash__() method for Ed25519Key
makes Ed25519Key objs comparable, needed for host keys
-rw-r--r--paramiko/ed25519key.py7
-rw-r--r--tests/test_pkey.py11
2 files changed, 17 insertions, 1 deletions
diff --git a/paramiko/ed25519key.py b/paramiko/ed25519key.py
index e1a8a732..a50d68bc 100644
--- a/paramiko/ed25519key.py
+++ b/paramiko/ed25519key.py
@@ -167,6 +167,13 @@ class Ed25519Key(PKey):
m.add_string(v.encode())
return m.asbytes()
+ def __hash__(self):
+ if self.can_sign():
+ v = self._signing_key.verify_key
+ else:
+ v = self._verifying_key
+ return hash((self.get_name(), v))
+
def get_name(self):
return "ssh-ed25519"
diff --git a/tests/test_pkey.py b/tests/test_pkey.py
index 6e589915..e614c777 100644
--- a/tests/test_pkey.py
+++ b/tests/test_pkey.py
@@ -455,9 +455,18 @@ class KeyTest(unittest.TestCase):
key2 = Ed25519Key.from_private_key_file(
test_path('test_ed25519_password.key'), b'abc123'
)
-
self.assertNotEqual(key1.asbytes(), key2.asbytes())
+ def test_ed25519_compare(self):
+ # verify that the private & public keys compare equal
+ key = Ed25519Key.from_private_key_file(test_path('test_ed25519.key'))
+ self.assertEqual(key, key)
+ pub = Ed25519Key(data=key.asbytes())
+ self.assertTrue(key.can_sign())
+ self.assertTrue(not pub.can_sign())
+ self.assertEqual(key, pub)
+
+
def test_keyfile_is_actually_encrypted(self):
# Read an existing encrypted private key
file_ = test_path('test_rsa_password.key')