Ejemplo n.º 1
0
void aligned_transform(KERNEL kernel, OUT_ITER out, OUT_ITER end, ARG_ITERS... args )
{
    using REAL = typename std::iterator_traits<OUT_ITER>::value_type;
    if(out == end)
        return;
    
    kernel(aligned_load(args)... ).aligned_store( &(*out) );
    out += pack_size<REAL>();
    while(out != end)
    {        
        kernel(aligned_load(advance_iter(args))... ).aligned_store( &(*out) );
        out += pack_size<REAL>();
    }
}
Ejemplo n.º 2
0
void aligned_transform(KERNEL kernel, std::size_t N, ITER itr, MORE_ITERS... itrs )
{
    using REAL = typename std::iterator_traits<ITER>::value_type;

    ITER end = itr+N;
    if(itr == end)
        return;
    
    {
        std::array< pack<REAL>, sizeof...(MORE_ITERS)+1 > packs{aligned_load(itr), aligned_load(itrs)... };
        kernel(packs);
        aligned_multi_store<OUTPUT_PARAMS>(packs, itr, itrs...);
        itr += pack_size<REAL>();
    }
    while(itr != end)
    {        
        std::array< pack<REAL>, sizeof...(MORE_ITERS)+1 > packs{aligned_load(itr), aligned_load(advance_iter(itrs))...};
        kernel(packs);
        aligned_multi_store<OUTPUT_PARAMS>(packs, itr, itrs...);
        itr += pack_size<REAL>();
    }
}
Ejemplo n.º 3
0
/**
 * gnutls_x509_trust_list_iter_get_ca:
 * @list: The structure of the list
 * @iter: A pointer to an iterator (initially the iterator should be %NULL)
 * @crt: where the certificate will be copied
 *
 * This function obtains a certificate in the trust list and advances the
 * iterator to the next certificate. The certificate returned in @crt must be
 * deallocated with gnutls_x509_crt_deinit().
 *
 * When past the last element is accessed %GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
 * is returned and the iterator is reset.
 *
 * After use, the iterator must be deinitialized usin
 *  gnutls_x509_trust_list_iter_deinit().
 *
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
 *   negative error value.
 *
 * Since: 3.4.0
 **/
int
gnutls_x509_trust_list_iter_get_ca(gnutls_x509_trust_list_t list,
                                   gnutls_x509_trust_list_iter_t *iter,
                                   gnutls_x509_crt_t *crt)
{
	int ret;

	/* initialize iterator */
	if (*iter == NULL) {
		*iter = gnutls_malloc(sizeof (struct gnutls_x509_trust_list_iter));
		if (*iter == NULL)
			return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);

		(*iter)->node_index = 0;
		(*iter)->ca_index = 0;

#ifdef ENABLE_PKCS11
		(*iter)->pkcs11_list = NULL;
		(*iter)->pkcs11_size = 0;
		(*iter)->pkcs11_index = 0;
#endif

		/* Advance iterator to the first valid entry */
		if (list->node[0].trusted_ca_size == 0) {
			ret = advance_iter(list, *iter);
			if (ret != 0) {
				gnutls_x509_trust_list_iter_deinit(*iter);
				*iter = NULL;

				*crt = NULL;
				return gnutls_assert_val(ret);
			}
		}
	}

	/* obtain the certificate at the current iterator position */
	if ((*iter)->node_index < list->size) {
		ret = gnutls_x509_crt_init(crt);
		if (ret < 0)
			return gnutls_assert_val(ret);

		ret = _gnutls_x509_crt_cpy(*crt, list->node[(*iter)->node_index].trusted_cas[(*iter)->ca_index]);
		if (ret < 0) {
			gnutls_x509_crt_deinit(*crt);
			return gnutls_assert_val(ret);
		}
	}
#ifdef ENABLE_PKCS11
	else if ( (*iter)->pkcs11_index < (*iter)->pkcs11_size) {
		ret = gnutls_x509_crt_init(crt);
		if (ret < 0)
			return gnutls_assert_val(ret);

		ret = gnutls_x509_crt_import_pkcs11(*crt, (*iter)->pkcs11_list[(*iter)->pkcs11_index]);
		if (ret < 0) {
			gnutls_x509_crt_deinit(*crt);
			return gnutls_assert_val(ret);
		}
	}
#endif

	else {
		/* iterator is at end */
		gnutls_x509_trust_list_iter_deinit(*iter);
		*iter = NULL;

		*crt = NULL;
		return gnutls_assert_val(GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE);
	}

	/* Move iterator to the next position.
	 * GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE is returned if the iterator
	 * has been moved to the end position. That is okay, we return the
	 * certificate that we read and when this function is called again we
	 * report GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE to our caller. */
	ret = advance_iter(list, *iter);
	if (ret	< 0 && ret != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) {
		gnutls_x509_crt_deinit(*crt);
		*crt = NULL;

		return gnutls_assert_val(ret);
	}

	return 0;
}