Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_ssh_key(key_path: str) -> bool:
if key_path and os.path.exists(key_path):
with open(key_path) as key:
contents = key.read()
key = sshpubkeys.SSHKey(contents)
try:
key.parse()
except (sshpubkeys.InvalidKeyError, NotImplementedError) as e:
return False
return True
return False