def METHOD_NAME(try_new_cert: bool, try_new_metadata: bool) -> Saml2Config:
    saml_path = Path(app.config["SAML_PATH"])
    if try_new_cert:
        saml_path /= "new"
    config_file = saml_path / "config.py"
    saml2_config = Saml2Config()
    # We load the config file manually so that we can fill it with the extra info
    try:
        globals_dict = globals().copy()
        locals_dict: dict = {}
        exec(config_file.read_text(), globals_dict, locals_dict)
        saml2_config.load_file(str(config_file))
        config_dict = locals_dict["CONFIG"]
    except FileNotFoundError:
        raise FileNotFoundError(f"Could not find SAML config file.")
    except KeyError:
        raise KeyError(f"Could not find CONFIG dict in SAML config file.")
    metadata_cert_file_name = (
        "metadata_new.crt" if try_new_metadata else "metadata.crt"
    )
    metadata_cert_file = saml_path / "certs" / metadata_cert_file_name
    sp_key = saml_path / "certs" / "sp.key"
    sp_cert = saml_path / "certs" / "sp.crt"
    if sp_key.exists() and sp_cert.exists():
        sp_key_str = str(sp_key)
        sp_cert_str = str(sp_cert)
        config_dict["key_file"] = sp_key_str
        config_dict["cert_file"] = sp_cert_str
        # Encryption keypairs seem to be a different option, but e.g., in HAKA the same keys are used for encrypting
        # requests and decrypting responses
        config_dict["encryption_keypairs"] = [
            {
                "key_file": sp_key_str,
                "cert_file": sp_cert_str,
            }
        ]
    config_dict["metadata"] = {
        "loadex": [
            {
                "loader": metadata_loader,
                "cert": str(saml_path / "certs" / metadata_cert_file)
                if app.config["SAML_VERIFY_METADATA"]
                else None,
            }
        ]
    }
    config_dict["attribute_map_dir"] = str(saml_path.parent / "attributemaps")
    config_dict["allow_unknown_attributes"] = True
    saml2_config.load(config_dict)
    return saml2_config