Skip to content

fix wrong error raised when private key is missing or invalid - #80

Open
shashfrankenstien wants to merge 4 commits into
byteskeptical:rootfrom
shashfrankenstien:keyless_problem
Open

fix wrong error raised when private key is missing or invalid#80
shashfrankenstien wants to merge 4 commits into
byteskeptical:rootfrom
shashfrankenstien:keyless_problem

Conversation

@shashfrankenstien

@shashfrankenstien shashfrankenstien commented Aug 7, 2026

Copy link
Copy Markdown

In the Connection class, if the private key file is not in key_types, or if the file path provided doesn't exist, it raises

UnboundLocalError: local variable 'key' referenced before assignment

This is because key.from_private_key_file is called in a finally block that will execute regardless of whether the try succeeds or fails. The correct branch to use is else.

Additionally, self._transport.auth_publickey and self._transport.auth_password were being called even when password and/or private_key inputs were not strings. This PR fixes this and raises CredentialException

Added required tests!

@byteskeptical byteskeptical self-assigned this Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants