+ cat > _check_gmime_cert.c <<EOF
+#include <stdio.h>
+#include <gmime/gmime.h>
+
+int main () {
+ GError *error = NULL;
+ GMimeParser *parser = NULL;
+ GMimeApplicationPkcs7Mime *body = NULL;
+ GMimeSignatureList *sig_list = NULL;
+ GMimeSignature *sig = NULL;
+ GMimeCertificate *cert = NULL;
+ GMimeObject *output = NULL;
+ int len;
+
+ g_mime_init ();
+ parser = g_mime_parser_new ();
+ g_mime_parser_init_with_stream (parser, g_mime_stream_file_open("$srcdir/test/corpora/pkcs7/smime-onepart-signed.eml", "r", &error));
+ if (error) return !! fprintf (stderr, "failed to instantiate parser with test/corpora/pkcs7/smime-onepart-signed.eml\n");
+
+ body = GMIME_APPLICATION_PKCS7_MIME(g_mime_message_get_mime_part (g_mime_parser_construct_message (parser, NULL)));
+ if (body == NULL) return !! fprintf (stderr, "did not find a application/pkcs7 message\n");
+
+ sig_list = g_mime_application_pkcs7_mime_verify (body, GMIME_VERIFY_NONE, &output, &error);
+ if (error || output == NULL) return !! fprintf (stderr, "verify failed\n");
+
+ if (sig_list == NULL) return !! fprintf (stderr, "no GMimeSignatureList found\n");
+ len = g_mime_signature_list_length (sig_list);
+ if (len != 1) return !! fprintf (stderr, "expected 1 signature, got %d\n", len);
+ sig = g_mime_signature_list_get_signature (sig_list, 0);
+ if (sig == NULL) return !! fprintf (stderr, "no GMimeSignature found at position 0\n");
+ cert = g_mime_signature_get_certificate (sig);
+ if (cert == NULL) return !! fprintf (stderr, "no GMimeCertificate found\n");
+#ifdef CHECK_VALIDITY
+ GMimeValidity validity = g_mime_certificate_get_id_validity (cert);
+ if (validity != GMIME_VALIDITY_FULL) return !! fprintf (stderr, "Got validity %d, expected %d\n", validity, GMIME_VALIDITY_FULL);
+#endif
+#ifdef CHECK_EMAIL
+ const char *email = g_mime_certificate_get_email (cert);
+ if (! email) return !! fprintf (stderr, "no email returned");
+ if (email[0] == '<') return 2;
+#endif
+ return 0;
+}