gnutls_pcert_list_import_x509_raw (gnutls_pcert_st * pcerts,
                             unsigned int *pcert_max,
                             const gnutls_datum_t * data,
                             gnutls_x509_crt_fmt_t format, unsigned int flags)
{
int ret;
unsigned int i = 0, j;
gnutls_x509_crt_t *crt;

  crt = gnutls_malloc((*pcert_max) * sizeof(gnutls_x509_crt_t));

  if (crt == NULL)
    return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);

  ret = gnutls_x509_crt_list_import( crt, pcert_max, data, format, flags);
  if (ret < 0)
    {
      ret = gnutls_assert_val(ret);
      goto cleanup;
    }
  
  for (i=0;i<*pcert_max;i++)
    {
      ret = gnutls_pcert_import_x509(&pcerts[i], crt[i], flags);
      if (ret < 0)
        {
          ret = gnutls_assert_val(ret);
          goto cleanup_pcert;
        }
    }

  ret = 0;
  goto cleanup;

cleanup_pcert:
  for (j=0;j<i;j++)
    gnutls_pcert_deinit(&pcerts[j]);

cleanup:
  for (i=0;i<*pcert_max;i++)
    gnutls_x509_crt_deinit(crt[i]);

  gnutls_free(crt);
  return ret;

}
gnutls_pcert_list_import_x509_raw (gnutls_pcert_st * pcerts,
                             unsigned int *pcert_max,
                             const gnutls_datum_t * data,
                             gnutls_x509_crt_fmt_t format, unsigned int flags)
{
int ret;
unsigned int i = 0, j;
gnutls_x509_crt_t *crt;

  crt = gnutls_malloc((*pcert_max) * sizeof(gnutls_x509_crt_t));

  if (crt == NULL)
    return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);

  ret = gnutls_x509_crt_list_import( crt, pcert_max, data, format, flags);
  if (ret < 0)
    {
      ret = gnutls_assert_val(ret);
      goto cleanup;
    }
  
  for (i=0;i<*pcert_max;i++)
    {
      ret = gnutls_pcert_import_x509(&pcerts[i], crt[i], flags);
      if (ret < 0)
        {
          ret = gnutls_assert_val(ret);
          goto cleanup_pcert;
        }
    }

  ret = 0;
  goto cleanup;

cleanup_pcert:
  for (j=0;j<i;j++)
    gnutls_pcert_deinit(&pcerts[j]);

cleanup:
  for (i=0;i<*pcert_max;i++)
    gnutls_x509_crt_deinit(crt[i]);

  gnutls_free(crt);
  return ret;

}