+/* Print signature flags */
+struct key_map_struct {
+ GMimeSignatureError bit;
+ const char * string;
+};
+
+static void
+do_format_signature_errors (sprinter_t *sp, struct key_map_struct *key_map,
+ unsigned int array_map_len, GMimeSignatureError errors) {
+ sp->map_key (sp, "errors");
+ sp->begin_map (sp);
+
+ for (unsigned int i = 0; i < array_map_len; i++) {
+ if (errors & key_map[i].bit) {
+ sp->map_key (sp, key_map[i].string);
+ sp->boolean (sp, true);
+ }
+ }
+
+ sp->end (sp);
+}
+
+#if (GMIME_MAJOR_VERSION < 3)
+static void
+format_signature_errors (sprinter_t *sp, GMimeSignature *signature)
+{
+ GMimeSignatureError errors = g_mime_signature_get_errors (signature);
+
+ if (errors == GMIME_SIGNATURE_ERROR_NONE)
+ return;
+
+ struct key_map_struct key_map[] = {
+ { GMIME_SIGNATURE_ERROR_EXPSIG, "sig-expired" },
+ { GMIME_SIGNATURE_ERROR_NO_PUBKEY, "key-missing"},
+ { GMIME_SIGNATURE_ERROR_EXPKEYSIG, "key-expired"},
+ { GMIME_SIGNATURE_ERROR_REVKEYSIG, "key-revoked"},
+ { GMIME_SIGNATURE_ERROR_UNSUPP_ALGO, "alg-unsupported"},
+ };
+
+ do_format_signature_errors (sp, key_map, ARRAY_SIZE(key_map), errors);
+}
+#else
+static void
+format_signature_errors (sprinter_t *sp, GMimeSignature *signature)
+{
+ GMimeSignatureError errors = g_mime_signature_get_errors (signature);
+
+ if (!(errors & GMIME_SIGNATURE_STATUS_ERROR_MASK))
+ return;
+
+ struct key_map_struct key_map[] = {
+ { GMIME_SIGNATURE_STATUS_KEY_REVOKED, "key-revoked"},
+ { GMIME_SIGNATURE_STATUS_KEY_EXPIRED, "key-expired"},
+ { GMIME_SIGNATURE_STATUS_SIG_EXPIRED, "sig-expired" },
+ { GMIME_SIGNATURE_STATUS_KEY_MISSING, "key-missing"},
+ { GMIME_SIGNATURE_STATUS_CRL_MISSING, "crl-missing"},
+ { GMIME_SIGNATURE_STATUS_CRL_TOO_OLD, "crl-too-old"},
+ { GMIME_SIGNATURE_STATUS_BAD_POLICY, "bad-policy"},
+ { GMIME_SIGNATURE_STATUS_SYS_ERROR, "sys-error"},
+ { GMIME_SIGNATURE_STATUS_TOFU_CONFLICT, "tofu-conflict"},
+ };
+
+ do_format_signature_errors (sp, key_map, ARRAY_SIZE(key_map), errors);
+}
+#endif
+