Beispiel #1
0
static void
format_part_sigstatus_json (const GMimeSignatureValidity* validity)
{
    printf (", \"sigstatus\": [");

    if (!validity) {
	printf ("]");
	return;
    }

    const GMimeSigner *signer = g_mime_signature_validity_get_signers (validity);
    int first = 1;
    void *ctx_quote = talloc_new (NULL);

    while (signer) {
	if (first)
	    first = 0;
	else
	    printf (", ");

	printf ("{");

	/* status */
	printf ("\"status\": %s",
		json_quote_str (ctx_quote,
				signer_status_to_string (signer->status)));

	if (signer->status == GMIME_SIGNER_STATUS_GOOD)
	{
	    if (signer->fingerprint)
		printf (", \"fingerprint\": %s", json_quote_str (ctx_quote, signer->fingerprint));
	    /* these dates are seconds since the epoch; should we
	     * provide a more human-readable format string? */
	    if (signer->created)
		printf (", \"created\": %d", (int) signer->created);
	    if (signer->expires)
		printf (", \"expires\": %d", (int) signer->expires);
	    /* output user id only if validity is FULL or ULTIMATE. */
	    /* note that gmime is using the term "trust" here, which
	     * is WRONG.  It's actually user id "validity". */
	    if ((signer->name) && (signer->trust)) {
		if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE))
		    printf (", \"userid\": %s", json_quote_str (ctx_quote, signer->name));
           }
       } else {
           if (signer->keyid)
               printf (", \"keyid\": %s", json_quote_str (ctx_quote, signer->keyid));
       }
       if (signer->errors != GMIME_SIGNER_ERROR_NONE) {
           printf (", \"errors\": %x", signer->errors);
       }

       printf ("}");
       signer = signer->next;
    }

    printf ("]");

    talloc_free (ctx_quote);
}
Beispiel #2
0
/* Signature status sprinter (GMime 2.4) */
static void
format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
{
    const GMimeSignatureValidity* validity = node->sig_validity;

    sp->begin_list (sp);

    if (!validity) {
	sp->end (sp);
	return;
    }

    const GMimeSigner *signer = g_mime_signature_validity_get_signers (validity);
    while (signer) {
	sp->begin_map (sp);

	/* status */
	sp->map_key (sp, "status");
	sp->string (sp, signer_status_to_string (signer->status));

	if (signer->status == GMIME_SIGNER_STATUS_GOOD)
	{
	    if (signer->fingerprint) {
		sp->map_key (sp, "fingerprint");
		sp->string (sp, signer->fingerprint);
	    }
	    /* these dates are seconds since the epoch; should we
	     * provide a more human-readable format string? */
	    if (signer->created) {
		sp->map_key (sp, "created");
		sp->integer (sp, signer->created);
	    }
	    if (signer->expires) {
		sp->map_key (sp, "expires");
		sp->integer (sp, signer->expires);
	    }
	    /* output user id only if validity is FULL or ULTIMATE. */
	    /* note that gmime is using the term "trust" here, which
	     * is WRONG.  It's actually user id "validity". */
	    if ((signer->name) && (signer->trust)) {
		if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE)) {
		    sp->map_key (sp, "userid");
		    sp->string (sp, signer->name);
		}
           }
       } else {
           if (signer->keyid) {
	       sp->map_key (sp, "keyid");
	       sp->string (sp, signer->keyid);
	   }
       }
       if (signer->errors != GMIME_SIGNER_ERROR_NONE) {
	   sp->map_key (sp, "errors");
	   sp->integer (sp, signer->errors);
       }

       sp->end (sp);
       signer = signer->next;
    }

    sp->end (sp);
}