# SPDX-FileCopyrightText: 2025 Marco Ricci <software@the13thletter.info>
#
# SPDX-License-Identifier: Zlib
"""A bare-bones SSH agent client supporting signing and key listing."""
from __future__ import annotations
import collections
import contextlib
import os
import socket
from typing import TYPE_CHECKING, overload
from typing_extensions import Self, assert_never
from derivepassphrase import _types
if TYPE_CHECKING:
from collections.abc import Iterable, Iterator, Sequence
from collections.abc import Set as AbstractSet
from types import TracebackType
from typing_extensions import Buffer
__all__ = ('SSHAgentClient',)
__author__ = 'Marco Ricci <software@the13thletter.info>'
# In SSH bytestrings, the "length" of the byte string is stored as
# a 4-byte/32-bit unsigned integer at the beginning.
HEAD_LEN = 4
_socket = socket
class TrailingDataError(RuntimeError):
"""The result contained trailing data."""
def __init__(self) -> None:
super().__init__('Overlong response from SSH agent')
class SSHAgentFailedError(RuntimeError):
"""The SSH agent failed to complete the requested operation."""
def __str__(self) -> str:
# Use match/case here once Python 3.9 becomes unsupported.
if self.args == ( # pragma: no branch
_types.SSH_AGENT.FAILURE.value,
b'',
):