webpg-npapi 0.6.1
std::string webpgPluginAPI::gpgGenKeyWorker ( const std::string &  key_type,
const std::string &  key_length,
const std::string &  subkey_type,
const std::string &  subkey_length,
const std::string &  name_real,
const std::string &  name_comment,
const std::string &  name_email,
const std::string &  expire_date,
const std::string &  passphrase,
void *  APIObj,
void(*)(void *self, const char *what, int type, int current, int total)  cb_status 
)

Creates a threaded worker to run the gpg keygen operation.

Parameters:
key_typeThe key type to genereate.
key_lengthThe size of the key to generate.
subkey_typeThe subkey type to generate.
subkey_lengthThe size of the subkey to genereate.
name_realThe name to assign the UID.
name_commentThe comment to assign to the UID.
name_emailThe email address to assign to the UID.
expire_dateThe expiration date to assign to the generated key.
passphraseThe passphrase to assign the to the key.
APIObjA reference to webpgPluginAPI.
cb_statusThe progress callback for the operation.

Definition at line 1960 of file webpgPluginAPI.cpp.

References get_gpgme_ctx().

Referenced by threaded_gpgGenKey().

{

    gpgme_ctx_t ctx = get_gpgme_ctx();
    gpgme_error_t err;
    std::string params = "<GnupgKeyParms format=\"internal\">\n"
        "Key-Type: " + key_type + "\n"
        "Key-Length: " + key_length + "\n"
        "Subkey-Type: " + subkey_type + "\n"
        "Subkey-Length: " + subkey_length + "\n"
        "Name-Real: " + name_real + "\n";
    if (name_comment.length() > 0) {
        params += "Name-Comment: " + name_comment + "\n";
    }
    if (name_email.length() > 0) {
        params += "Name-Email: " + name_email + "\n";
    }
    if (expire_date.length() > 0) {
        params += "Expire-Date: " + expire_date + "\n";
    } else {
        params += "Expire-Date: 0\n";
    }
    if (passphrase.length() > 0) {
        params += "Passphrase: " + passphrase + "\n";
    }
    params += "</GnupgKeyParms>\n";
    const char *parms = params.c_str();

    gpgme_genkey_result_t result;

    gpgme_set_progress_cb (ctx, cb_status, APIObj);

    err = gpgme_op_genkey (ctx, parms, NULL, NULL);
    if (err)
        return "Error with genkey start" + err;

    result = gpgme_op_genkey_result (ctx);

    if (!result)
    {
#ifdef DEBUG
        fprintf (stderr, "%s:%d: gpgme_op_genkey_result returns NULL\n",
           __FILE__, __LINE__);
#endif
        return "error with result";
    }

#ifdef DEBUG
    printf ("Generated key: %s (%s)\n", result->fpr ? result->fpr : "none",
        result->primary ? (result->sub ? "primary, sub" : "primary")
        : (result->sub ? "sub" : "none"));
#endif

    gpgme_release (ctx);
    const char* status = (char *) "complete";
    cb_status(APIObj, status, 33, 33, 33);
    return "done";
}

Here is the call graph for this function:

 All Classes Functions