void test_tls_write_cert_chain(const char *filename,

                               gnutls_x509_crt_t *certs,

                               size_t ncerts)

{

    size_t i;

    size_t capacity = 1024, offset = 0;

    char *buffer = g_new0(char, capacity);

    int err;



    for (i = 0; i < ncerts; i++) {

        size_t len = capacity - offset;

    retry:

        err = gnutls_x509_crt_export(certs[i], GNUTLS_X509_FMT_PEM,

                                     buffer + offset, &len);

        if (err < 0) {

            if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) {

                buffer = g_renew(char, buffer, offset + len);

                capacity = offset + len;

                goto retry;

            }

            g_critical("Failed to export certificate chain %s: %d",

                       gnutls_strerror(err), err);

            abort();

        }

        offset += len;

    }



    if (!g_file_set_contents(filename, buffer, offset, NULL)) {

        abort();

    }


}
void test_tls_write_cert_chain(const char *filename,

                               gnutls_x509_crt_t *certs,

                               size_t ncerts)

{

    size_t i;

    size_t capacity = 1024, offset = 0;

    char *buffer = g_new0(char, capacity);

    int err;



    for (i = 0; i < ncerts; i++) {

        size_t len = capacity - offset;

    retry:

        err = gnutls_x509_crt_export(certs[i], GNUTLS_X509_FMT_PEM,

                                     buffer + offset, &len);

        if (err < 0) {

            if (err == GNUTLS_E_SHORT_MEMORY_BUFFER) {

                buffer = g_renew(char, buffer, offset + len);

                capacity = offset + len;

                goto retry;

            }

            g_critical("Failed to export certificate chain %s: %d",

                       gnutls_strerror(err), err);

            abort();

        }

        offset += len;

    }



    if (!g_file_set_contents(filename, buffer, offset, NULL)) {

        abort();

    }


}
void FUNC_0(const char *VAR_0,

                               gnutls_x509_crt_t *VAR_1,

                               size_t VAR_2)

{

    size_t i;

    size_t capacity = 1024, offset = 0;

    char *VAR_3 = g_new0(char, capacity);

    int VAR_4;



    for (i = 0; i < VAR_2; i++) {

        size_t len = capacity - offset;

    retry:

        VAR_4 = gnutls_x509_crt_export(VAR_1[i], GNUTLS_X509_FMT_PEM,

                                     VAR_3 + offset, &len);

        if (VAR_4 < 0) {

            if (VAR_4 == GNUTLS_E_SHORT_MEMORY_BUFFER) {

                VAR_3 = g_renew(char, VAR_3, offset + len);

                capacity = offset + len;

                goto retry;

            }

            g_critical("Failed to export certificate chain %s: %d",

                       gnutls_strerror(VAR_4), VAR_4);

            abort();

        }

        offset += len;

    }



    if (!g_file_set_contents(VAR_0, VAR_3, offset, NULL)) {

        abort();

    }


}
void FUNC_0(const char *VAR_0,
gnutls_x509_crt_t *VAR_1,
size_t VAR_2)
{ size_t i; size_t capacity = 1024, offset = 0; char *VAR_3 = g_new0(char, capacity); int VAR_4; for (i = 0; i < VAR_2; i++) { size_t len = capacity - offset; retry:
VAR_4 = gnutls_x509_crt_export(VAR_1[i], GNUTLS_X509_FMT_PEM,
VAR_3 + offset, &len); if (VAR_4 < 0) { if (VAR_4 == GNUTLS_E_SHORT_MEMORY_BUFFER) { VAR_3 = g_renew(char, VAR_3, offset + len); capacity = offset + len; goto retry; } g_critical("Failed to export certificate chain %s: %d",
gnutls_strerror(VAR_4), VAR_4); abort(); } offset += len; } if (!g_file_set_contents(VAR_0, VAR_3, offset, NULL)) { abort(); } }