_gnutls_session_cert_type_supported(gnutls_session_t session,
				    gnutls_certificate_type_t cert_type,
				    bool check_credentials,
				    gnutls_ctype_target_t target)
{
	unsigned i;
	priority_st* ctype_priorities;

	// Check whether this cert type is enabled by the application
	if (!is_cert_type_enabled(session, cert_type))
		return gnutls_assert_val(GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE);

	// Perform a credentials check if requested
	if (check_credentials)	{
		if (!_gnutls_has_cert_credentials(session, cert_type))
			return gnutls_assert_val(GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE);
	}

	/* So far so good. We have the required credentials (if needed).
	 * Now check whether we are allowed to use them according to our
	 * priorities.
	 */
	// Which certificate type should we query?
	switch (target) {
		case GNUTLS_CTYPE_CLIENT:
			ctype_priorities =
					&(session->internals.priorities->client_ctype);
			break;
		case GNUTLS_CTYPE_SERVER:
			ctype_priorities =
					&(session->internals.priorities->server_ctype);
			break;
		default:
			return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
	}

	// No explicit priorities set, and default ctype is asked
	if (ctype_priorities->num_priorities == 0
	    && cert_type == DEFAULT_CERT_TYPE)
		return 0;

	/* Now lets find out whether our cert type is in our priority
	 * list, i.e. set of allowed cert types.
	 */
	for (i = 0; i < ctype_priorities->num_priorities; i++) {
		if (ctype_priorities->priorities[i] == cert_type)
			return 0;
	}

	return GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE;
}
_gnutls_session_cert_type_supported(gnutls_session_t session,
				    gnutls_certificate_type_t cert_type,
				    bool check_credentials,
				    gnutls_ctype_target_t target)
{
	unsigned i;
	priority_st* ctype_priorities;

	 
	if (!is_cert_type_enabled(session, cert_type))
		return gnutls_assert_val(GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE);

	 
	if (check_credentials)	{
		if (!_gnutls_has_cert_credentials(session, cert_type))
			return gnutls_assert_val(GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE);
	}

	 
	 
	switch (target) {
		case GNUTLS_CTYPE_CLIENT:
			ctype_priorities =
					&(session->internals.priorities->client_ctype);
			break;
		case GNUTLS_CTYPE_SERVER:
			ctype_priorities =
					&(session->internals.priorities->server_ctype);
			break;
		default:
			return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
	}

	 
	if (ctype_priorities->num_priorities == 0
	    && cert_type == DEFAULT_CERT_TYPE)
		return 0;

	 
	for (i = 0; i < ctype_priorities->num_priorities; i++) {
		if (ctype_priorities->priorities[i] == cert_type)
			return 0;
	}

	return GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE;
}