How to use the sshpubkeys.exceptions 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 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