def parse_rsa_algorithm(algorithm):
    """
    Parses a RSA algorithm and returns tuple (hash, padding).

    :param algorithm: string, RSA algorithm as defined at
        https://tools.ietf.org/html/rfc7518#section-3.1.
    :raises: UnsupportedAlgorithm: if the algorithm is not supported.
    :returns: (hash, padding) tuple.
    """

    if algorithm == "RS256":
        return hashes.SHA256(), padding.PKCS1v15()
    elif algorithm == "RS384":
        return hashes.SHA384(), padding.PKCS1v15()
    elif algorithm == "RS512":
        return hashes.SHA512(), padding.PKCS1v15()
    elif algorithm == "PS256":
        return (hashes.SHA256(),
                padding.PSS(
                    mgf=padding.MGF1(hashes.SHA256()),
                    salt_length=padding.PSS.MAX_LENGTH))
    elif algorithm == "PS384":
        return (hashes.SHA384(),
                padding.PSS(
                    mgf=padding.MGF1(hashes.SHA384()),
                    salt_length=padding.PSS.MAX_LENGTH))
    elif algorithm == "PS512":
        return (hashes.SHA512(),
                padding.PSS(
                    mgf=padding.MGF1(hashes.SHA512()),
                    salt_length=padding.PSS.MAX_LENGTH))
    else:
        raise UnsupportedAlgorithm("Unknown algorithm: {}".format(algorithm))
def parse_rsa_algorithm ( algorithm ) : if algorithm == "RS256" : return hashes . SHA256 ( ) , padding . PKCS1v15 ( ) elif algorithm == "RS384" : return hashes . SHA384 ( ) , padding . PKCS1v15 ( ) elif algorithm == "RS512" : return hashes . SHA512 ( ) , padding . PKCS1v15 ( ) elif algorithm == "PS256" : return ( hashes . SHA256 ( ) , padding . PSS ( mgf = padding . MGF1 ( hashes . SHA256 ( ) ) , salt_length = padding . PSS . MAX_LENGTH ) ) elif algorithm == "PS384" : return ( hashes . SHA384 ( ) , padding . PSS ( mgf = padding . MGF1 ( hashes . SHA384 ( ) ) , salt_length = padding . PSS . MAX_LENGTH ) ) elif algorithm == "PS512" : return ( hashes . SHA512 ( ) , padding . PSS ( mgf = padding . MGF1 ( hashes . SHA512 ( ) ) , salt_length = padding . PSS . MAX_LENGTH ) ) else : raise UnsupportedAlgorithm ( "Unknown algorithm: {}" . format ( algorithm ) )
Parses a RSA algorithm and returns tuple (hash, padding).

    :param algorithm: string, RSA algorithm as defined at
        https://tools.ietf.org/html/rfc7518#section-3.1.
    :raises: UnsupportedAlgorithm: if the algorithm is not supported.
    :returns: (hash, padding) tuple.