webpg-npapi 0.6.1
|
Signs the text specified in plain_text with the key ids specified in signers, with the signature mode specified in sign_mode.
response { "data":"—————BEGIN PGP SIGNED MESSAGE————— Hash: SHA1 This is some text to sign... —————BEGIN PGP SIGNATURE————— Version: GnuPG v1.4.11 (GNU/Linux) iQEcBAEBAgAGBQJQTQWwAAoJEMWZcR9egruTsp8H/A/qNCyzSsoVR+VeQQTEBcfi OpJkwQ5BCm2/5ZdlFATijaHe3s1C2OYUmncb3Z+OIIy8FNzCuMboNl83m5ro0Ng8 IgSAcVJpLlVwbkAfGyWqmQ48yS7gDqb0pUSgkhEgCnMn+yDtFWPgAVTiKpuWJpf8 NiIO1cNm+3RwSnftSxGDLTUu3UoXh7BZXnoOMa63fUukF3duzIrIUhav8zg/Vfrb JK7tC2UPRGJCVREr/2EEYvpasHxHX2yJpT+cYM1ChCGgo+Kd3OX4sDRAALZ+7Gwm NdrvT57QxQ7Y/cSd5H+c3/vpYzSwwmXmK+/m3uVUHIdccOvGNg7vNg8aYSfR1FY= =v9Ab —————END PGP SIGNATURE—————", "error":false } Definition at line 1585 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 in, out; gpgme_key_t key; gpgme_sig_mode_t sig_mode; gpgme_sign_result_t sign_result; int nsigners; FB::variant signer; FB::VariantMap result; if (sign_mode == 0) sig_mode = GPGME_SIG_MODE_NORMAL; else if (sign_mode == 1) sig_mode = GPGME_SIG_MODE_DETACH; else if (sign_mode == 2) sig_mode = GPGME_SIG_MODE_CLEAR; for (nsigners=0; nsigners < signers.size(); nsigners++) { signer = signers[nsigners]; err = gpgme_op_keylist_start (ctx, signer.convert_cast<std::string>().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_signers_add (ctx, key); if (err != GPG_ERR_NO_ERROR) return get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__); gpgme_key_unref (key); } if (!nsigners > 0) return get_error_map(__func__, -1, "No signing keys found", __LINE__, __FILE__); err = gpgme_data_new_from_mem (&in, plain_text.c_str(), plain_text.length(), 0); 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__); err = gpgme_op_sign(ctx, in, out, sig_mode); if (err != GPG_ERR_NO_ERROR) return get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__); sign_result = gpgme_op_sign_result (ctx); if (!sign_result) return get_error_map(__func__, gpgme_err_code (err), "The signed result is invalid", __LINE__, __FILE__); gpgme_data_seek(out, 0, SEEK_SET); size_t out_size = 0; std::string out_buf; out_buf = gpgme_data_release_and_get_mem (out, &out_size); /* strip the size_t data out of the output buffer */ out_buf = out_buf.substr(0, out_size); /* set the output object to NULL since it has already been released */ out = NULL; result["error"] = false; result["data"] = out_buf; gpgme_data_release (in); gpgme_release (ctx); return result; }
Here is the call graph for this function:
|