summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2023-05-16 21:04:55 -0400
committerJeff Forcier <jeff@bitprophet.org>2023-05-18 13:57:19 -0400
commit41ce1ac25928a647e819d11e181d788d4a495c5a (patch)
tree1ccdf9451fbe43ec19b02a004d2f41f1bd5e3bb1
parentfeb48c3792f1c54d189d04cd66364e5728ffe6bd (diff)
Implement _fields on AgentKey so __eq__ works correctly
-rw-r--r--paramiko/agent.py3
-rw-r--r--sites/www/changelog.rst2
-rw-r--r--tests/agent.py24
3 files changed, 28 insertions, 1 deletions
diff --git a/paramiko/agent.py b/paramiko/agent.py
index 2171ff71..8486d6ca 100644
--- a/paramiko/agent.py
+++ b/paramiko/agent.py
@@ -475,7 +475,8 @@ class AgentKey(PKey):
@property
def _fields(self):
- raise NotImplementedError
+ fallback = [self.get_name(), self.blob]
+ return self.inner_key._fields if self.inner_key else fallback
def sign_ssh_data(self, data, algorithm=None):
msg = Message()
diff --git a/sites/www/changelog.rst b/sites/www/changelog.rst
index 43f81115..5f085131 100644
--- a/sites/www/changelog.rst
+++ b/sites/www/changelog.rst
@@ -2,6 +2,8 @@
Changelog
=========
+- :feature:`-` Implement ``_fields()`` on `~paramiko.agent.AgentKey` so that it
+ may be compared (via ``==``) with other `~paramiko.pkey.PKey` instances.
- :bug:`23 major` Since its inception, Paramiko has (for reasons lost to time)
implemented authentication as a side effect of handling affirmative replies
to ``MSG_SERVICE_REQUEST`` protocol messages. What this means is Paramiko
diff --git a/tests/agent.py b/tests/agent.py
new file mode 100644
index 00000000..18ece7a9
--- /dev/null
+++ b/tests/agent.py
@@ -0,0 +1,24 @@
+from paramiko import AgentKey
+
+
+class AgentKey_:
+ class fields:
+ """
+ _fields
+ """
+
+ def defaults_to_get_name_and_blob(self):
+ # Manually construct a 'failed to get inner_key' obj
+ class FallbackAgentKey(AgentKey):
+ def __init__(self, name, blob):
+ self.name = name
+ self.blob = blob
+ self.inner_key = None
+
+ key = FallbackAgentKey(name="lol", blob=b"lmao")
+ assert key._fields == ["lol", b"lmao"]
+
+ def defers_to_inner_key_when_present(self, keys):
+ key = AgentKey(agent=None, blob=keys.pkey.asbytes())
+ assert key._fields == keys.pkey._fields
+ assert key == keys.pkey