/*
* Copyright (C) 2017 Nikos Mavrogiannopoulos
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of GnuTLS.
*
* GnuTLS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* GnuTLS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see
*/
/* This tests key import for gnutls_x509_privkey_t APIs */
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "cert-common.h"
#include "utils.h"
#define testfail(fmt, ...) \
fail("%s: "fmt, name, ##__VA_ARGS__)
#define MAX_CERTS 8
static void load_list(const char *name, const gnutls_datum_t *txt,
unsigned int ncerts,
unsigned int max1,
unsigned int max2,
unsigned flags, int exp_err)
{
gnutls_x509_crt_t certs[MAX_CERTS];
unsigned int max, i;
unsigned retried = 0;
int ret;
assert(max1<=MAX_CERTS);
assert(max2<=MAX_CERTS);
if (max1)
max = max1;
else
max = MAX_CERTS;
retry:
ret = gnutls_x509_crt_list_import(certs, &max, txt, GNUTLS_X509_FMT_PEM, flags);
if (ret < 0) {
if (retried == 0 && ret == GNUTLS_E_SHORT_MEMORY_BUFFER && max2 && max2 != max) {
max = max2;
retried = 1;
goto retry;
}
if (exp_err == ret)
return;
testfail("gnutls_x509_crt_list_import: %s\n", gnutls_strerror(ret));
}
for (i=0;i