Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse(self, file_obj, **kwargs):
for line in file_obj:
line = line.strip()
if not line:
continue
if line.startswith("#"):
continue
ssh_key = SSHKey(line, **kwargs)
ssh_key.parse()
self.keys.append(ssh_key)
def rsa_public_key_parse(key_material):
try:
if not isinstance(key_material, six.binary_type):
key_material = key_material.encode("ascii")
decoded_key = base64.b64decode(key_material).decode("ascii")
public_key = SSHKey(decoded_key)
except (sshpubkeys.exceptions.InvalidKeyException, UnicodeDecodeError):
raise ValueError("bad key")
if not public_key.rsa:
raise ValueError("bad key")
return public_key.rsa