# Buggy code
def get_private_keys():
    """Find SSH keys in standard folder."""
    key_formats = [RSAKey, ECDSAKey, Ed25519Key]

    ssh_folder = os.path.expanduser("~/.ssh")

    available_private_keys = []
    if os.path.isdir(ssh_folder):
        for key in os.listdir(ssh_folder):
            key_file = os.path.join(ssh_folder, key)
            if not os.path.isfile(key_file):
                continue
            for key_format in key_formats:
                try:
                    parsed_key = key_format.from_private_key_file(key_file)
                    key_details = {
                        "filename": key,
                        "format": parsed_key.get_name(),
                        "bits": parsed_key.get_bits(),
                        "fingerprint": parsed_key.get_fingerprint().hex(),
                    }
                    available_private_keys.append(key_details)
                except (
                    SSHException,
                    UnicodeDecodeError,
                    IsADirectoryError,
                    IndexError,
                ):
                    continue
                except OSError as e:
                    if e.errno == errno.ENXIO:
                        # when key_file is a (ControlPath) socket
                        continue
                    else:
                        raise

    return available_private_keys


# Traceback (ValueError)
2020-11-24 00:24:57,883 - vorta.i18n - DEBUG - Loading translation succeeded for ['de', 'de-DE', 'de-Latn-DE'].
2020-11-24 00:24:57,912 - apscheduler.scheduler - INFO - Scheduler started
2020-11-24 00:24:57,914 - apscheduler.scheduler - INFO - Added job "VortaScheduler.create_backup" to job store "default"
2020-11-24 00:24:57,914 - vorta.scheduler - DEBUG - New job for profile Default was added.
2020-11-24 00:24:57,981 - vorta.borg.borg_thread - INFO - Running command /usr/local/bin/borg --version
CoreSVG has logged an error. Set environment variabe "CORESVG_VERBOSE" to learn more.
Traceback (most recent call last):
File "application.py", line 90, in open_main_window_action
File "views/main_window.py", line 47, in __init__
File "views/repo_tab.py", line 54, in __init__
File "views/repo_tab.py", line 100, in init_ssh
File "utils.py", line 84, in get_private_keys
File "paramiko/pkey.py", line 235, in from_private_key_file
File "paramiko/rsakey.py", line 55, in __init__
File "paramiko/rsakey.py", line 176, in _from_private_key_file
File "paramiko/rsakey.py", line 194, in _decode_key
File "cryptography/hazmat/primitives/asymmetric/rsa.py", line 308, in private_key
File "cryptography/hazmat/backends/openssl/backend.py", line 517, in load_rsa_private_numbers
File "cryptography/hazmat/primitives/asymmetric/rsa.py", line 171, in _check_private_key_components
ValueError: p*q must equal modulus.
zsh: abort      /Applications/Vorta.app/Contents/MacOS/vorta-darwin

# Fixed code
def get_private_keys():
    """Find SSH keys in standard folder."""
    key_formats = [RSAKey, ECDSAKey, Ed25519Key]

    ssh_folder = os.path.expanduser("~/.ssh")

    available_private_keys = []
    if os.path.isdir(ssh_folder):
        for key in os.listdir(ssh_folder):
            key_file = os.path.join(ssh_folder, key)
            if not os.path.isfile(key_file):
                continue
            for key_format in key_formats:
                try:
                    parsed_key = key_format.from_private_key_file(key_file)
                    key_details = {
                        "filename": key,
                        "format": parsed_key.get_name(),
                        "bits": parsed_key.get_bits(),
                        "fingerprint": parsed_key.get_fingerprint().hex(),
                    }
                    available_private_keys.append(key_details)
                except (
                    SSHException,
                    UnicodeDecodeError,
                    IsADirectoryError,
                    IndexError,
                    ValueError,
                    PermissionError,
                ):
                    continue
                except OSError as e:
                    if e.errno == errno.ENXIO:
                        # when key_file is a (ControlPath) socket
                        continue
                    else:
                        raise

    return available_private_keys