+static int delete_certfile(const char *file, const char *desc)
+{
+ if (file == NULL)
+ return 1;
+
+ if (unlink(file) != 0 && errno != ENOENT) {
+ CMP_err2("Failed to delete %s, which should be done to indicate there is no %s cert",
+ file, desc);
+ return 0;
+ }
+ return 1;
+}
+
+static int save_cert(OSSL_CMP_CTX *ctx, X509 *cert,
+ const char *file, const char *desc)
+{
+ if (file == NULL || cert == NULL) {
+ return 1;
+ } else {
+ STACK_OF(X509) *certs = sk_X509_new_null();
+
+ if (!X509_add_cert(certs, cert, X509_ADD_FLAG_UP_REF)) {
+ sk_X509_free(certs);
+ return 0;
+ }
+ return save_free_certs(ctx, certs, file, desc) >= 0;
+ }
+}
+