How to use the sshpubkeys.keys.SSHKey function in sshpubkeys

To help you get started, we’ve selected a few sshpubkeys examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ojarva / python-sshpubkeys / sshpubkeys / keys.py View on Github external
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)
github spulec / moto / moto / ec2 / utils.py View on Github external
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