webpg-npapi 0.6.1
FB::variant webpgPluginAPI::gpgSetPrimaryUID ( const std::string &  keyid,
long  uid_idx 
)

Sets a given UID as the primary for the key specified with keyid.

Parameters:
keyidThe ID of the key with the UID to make primary.
uid_idxThe index of the UID to make primary on the key.

Definition at line 2623 of file webpgPluginAPI.cpp.

References get_gpgme_ctx().

Referenced by webpgPluginAPI().

{
    gpgme_ctx_t ctx = get_gpgme_ctx();
    gpgme_error_t err;
    gpgme_data_t out = NULL;
    gpgme_key_t key = NULL;
    FB::VariantMap response;

    if (uid_idx < 1) {
        response["error"] = true;
        response["result"] = "UID index is always above zero, something is amiss...";
        return response;
    }

    current_uid = i_to_str(uid_idx);

    err = gpgme_op_keylist_start (ctx, keyid.c_str(), 0);
    if (err != GPG_ERR_NO_ERROR)
        return get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    err = gpgme_op_keylist_next (ctx, &key);
    if (err != GPG_ERR_NO_ERROR)
        return get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    err = gpgme_op_keylist_end (ctx);
    if (err != GPG_ERR_NO_ERROR)
        return get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    err = gpgme_data_new (&out);
    if (err != GPG_ERR_NO_ERROR)
        return get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    edit_status = "gpgSetPrimaryUID(keyid='" + keyid + "', uid_idx='" + i_to_str(uid_idx) + "');\n";
    err = gpgme_op_edit (ctx, key, edit_fnc_set_primary_uid, out, out);
    if (err != GPG_ERR_NO_ERROR)
        return get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);


    current_uid = "0";

    gpgme_data_release (out);
    gpgme_key_unref (key);
    gpgme_release (ctx);

    response["error"] = false;
    response["edit_status"] = edit_status;
    response["result"] = "Primary UID changed";

    return response;
}

Here is the call graph for this function:

 All Classes Functions