Introduce TrailingDataError for trailing data in SSH agent responses
Marco Ricci

Marco Ricci commited on 2024-06-30 16:37:52
Zeige 2 geänderte Dateien mit 14 Einfügungen und 4 Löschungen.

... ...
@@ -23,6 +23,9 @@ __version__ = "0.1.0"
23 23
 
24 24
 _socket = socket
25 25
 
26
+class TrailingDataError(RuntimeError):
27
+    """The result contained trailing data."""
28
+
26 29
 class SSHAgentClient:
27 30
     """A bare-bones SSH agent client supporting signing and key listing.
28 31
 
... ...
@@ -252,8 +255,10 @@ class SSHAgentClient:
252 255
         Raises:
253 256
             EOFError:
254 257
                 The response from the SSH agent is truncated or missing.
255
-            RuntimeError:
258
+            TrailingDataError:
256 259
                 The response from the SSH agent is too long.
260
+            RuntimeError:
261
+                The agent failed to complete the request.
257 262
 
258 263
         """
259 264
         response_code, response = self.request(
... ...
@@ -286,7 +291,7 @@ class SSHAgentClient:
286 291
             # Both `key` and `comment` are not wrapped as SSH strings.
287 292
             keys.append(KeyCommentPair(key, comment))
288 293
         if response_stream:
289
-            raise RuntimeError('overlong response from SSH agent')
294
+            raise TrailingDataError('overlong response from SSH agent')
290 295
         return keys
291 296
 
292 297
     def sign(
... ...
@@ -319,7 +324,7 @@ class SSHAgentClient:
319 324
         Raises:
320 325
             EOFError:
321 326
                 The response from the SSH agent is truncated or missing.
322
-            RuntimeError:
327
+            TrailingDataError:
323 328
                 The response from the SSH agent is too long.
324 329
             RuntimeError:
325 330
                 The agent failed to complete the request.
... ...
@@ -273,7 +273,12 @@ class TestAgentInteraction:
273 273
         [
274 274
             (255, b'', RuntimeError, 'error return from SSH agent:'),
275 275
             (12, b'\x00\x00\x00\x01', EOFError, 'truncated response'),
276
-            (12, b'\x00\x00\x00\x00abc', RuntimeError, 'overlong response'),
276
+            (
277
+                12,
278
+                b'\x00\x00\x00\x00abc',
279
+                ssh_agent_client.TrailingDataError,
280
+                'overlong response',
281
+            ),
277 282
         ]
278 283
     )
279 284
     def test_320_list_keys_error_responses(self, monkeypatch, response_code,
280 285