예제 #1
0
static char * geanypg_result(gpgme_signature_t sig)
{
    char format[] =
    "status ....: %s\n"
    "summary ...:%s\n"
    "fingerprint: %s\n"
    "created ...: %s"
    "expires ...: %s"
    "validity ..: %s\n"
    "val.reason : %s\n"
    "pubkey algo: %s\n"
    "digest algo: %s\n"
    "pka address: %s\n"
    "pka trust .: %s\n"
    "other flags:%s%s\n"
    "notations .: %s\n"; // 210 characters
    char * buffer = (char *)calloc(2048, 1); // everything together probably won't be more
                                          // than 1061 characters, but we don't want to
                                          // take risks
    char summary[128];
    const char * pubkey = gpgme_pubkey_algo_name(sig->pubkey_algo);
    const char * hash = gpgme_hash_algo_name(sig->hash_algo);
    char created[64];
    char expires[64];
    if (sig->timestamp)
        strncpy(created, ctime((time_t*)&sig->timestamp), 64);
    else
        strcpy(created, "Unknown\n");

    if (sig->exp_timestamp)
        strncpy(expires, ctime((time_t*)&sig->exp_timestamp), 64);
    else
        strcpy(expires, "Unknown\n");

    memset(summary, 0, 128);
    sprintf(buffer, format,
        gpgme_strerror(sig->status),            // probably won't be more than 128
        geanypg_summary(sig->summary, summary), // max 105 characters
        sig->fpr ? sig->fpr : "[None]",         // max 40 characters
        created,                                // probably about 24 characters
        expires,                                // probably about 24 characters
        geanypg_validity(sig->validity),        // max 11 characters
        gpgme_strerror(sig->status),            // probably won't be more than 128
        pubkey ? pubkey : "Unknown",            // probably won't be more than 32
        hash ? hash : "Unknown",            // probably won't be more than 32
        sig->pka_address ? sig->pka_address : "[None]", // probably won't be more than 128
        sig->pka_trust == 0 ? "n/a" : sig->pka_trust == 1 ? "bad" : sig->pka_trust == 2 ? "okay": "RFU", // max 4 characters
        sig->wrong_key_usage ? " wrong-key-usage" : "", sig->chain_model ? " chain-model" : "",          // max 28 characters
        sig->notations ? "yes" : "no");         // max 3 characters
    return buffer;
}
예제 #2
0
static char * geanypg_result(gpgme_signature_t sig)
{
    char * format =
    _("status ....: %s\n"
      "summary ...:%s\n"
      "fingerprint: %s\n"
      "created ...: %s"
      "expires ...: %s"
      "validity ..: %s\n"
      "val.reason : %s\n"
      "pubkey algo: %s\n"
      "digest algo: %s\n"
      "pka address: %s\n"
      "pka trust .: %s\n"
      "other flags:%s%s\n"
      "notations .: %s\n");
    char * buffer;
    char summary[128];
    const char * pubkey = gpgme_pubkey_algo_name(sig->pubkey_algo);
    const char * hash = gpgme_hash_algo_name(sig->hash_algo);
    char created[64];
    char expires[64];
    size_t buffer_size;
    if (sig->timestamp)
        strncpy(created, ctime((time_t*)&sig->timestamp), 64);
    else
        strcpy(created, _("Unknown\n"));

    if (sig->exp_timestamp)
        strncpy(expires, ctime((time_t*)&sig->exp_timestamp), 64);
    else
        strcpy(expires, _("Unknown\n"));

    buffer_size = strlen(format) +
        strlen(gpgme_strerror(sig->status)) +
        strlen(geanypg_summary(sig->summary, summary)) +
        strlen(sig->fpr ? sig->fpr : _("[None]")) +
        strlen(created) +
        strlen(expires) +
        strlen(geanypg_validity(sig->validity)) +
        strlen(gpgme_strerror(sig->status)) +
        strlen(pubkey ? pubkey : _("Unknown")) +
        strlen(hash ? hash : _("Unknown")) +
        strlen(sig->pka_address ? sig->pka_address : _("[None]")) +
        strlen(sig->pka_trust == 0 ? _("n/a") : sig->pka_trust == 1 ? _("bad") : sig->pka_trust == 2 ? _("okay"): _("RFU")) +
        strlen(sig->wrong_key_usage ? _(" wrong-key-usage") : "") +
        strlen(sig->chain_model ? _(" chain-model") : "") +
        strlen(sig->notations ? _("yes") : _("no")) + 1; // and a trailing \0

    buffer = (char *)calloc(buffer_size, 1);
    memset(summary, 0, 128);
    sprintf(buffer, format,
        gpgme_strerror(sig->status),
        geanypg_summary(sig->summary, summary),
        sig->fpr ? sig->fpr : _("[None]"),
        created,
        expires,
        geanypg_validity(sig->validity),
        gpgme_strerror(sig->status),
        pubkey ? pubkey : _("Unknown"),
        hash ? hash : _("Unknown"),
        sig->pka_address ? sig->pka_address : _("[None]"),
        sig->pka_trust == 0 ? _("n/a") : sig->pka_trust == 1 ? _("bad") : sig->pka_trust == 2 ? _("okay"): _("RFU"),
        sig->wrong_key_usage ? _(" wrong-key-usage") : "", sig->chain_model ? _(" chain-model") : "",
        sig->notations ? _("yes") : _("no"));
    return buffer;
}