37 #include <boost/format.hpp>
44 gpgme_check_version(0);
46 setlocale(LC_ALL,
"");
47 gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
49 gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL));
53 void getGpgKey(gpgme_ctx_t& ctx, std::string
const& user, gpgme_key_t& key) {
56 if (user == std::string(
"*")) {
57 err = gpgme_op_keylist_start(ctx, 0, 0);
59 err = gpgme_op_keylist_start(ctx, user.c_str(), 0);
62 throw BagException((boost::format(
"gpgme_op_keylist_start returned %1%") % gpgme_strerror(err)).str());
65 err = gpgme_op_keylist_next(ctx, &key);
67 if (user == std::string(
"*") || strcmp(key->uids->name, user.c_str()) == 0) {
70 gpgme_key_release(key);
71 }
else if (gpg_err_code(err) == GPG_ERR_EOF) {
72 if (user == std::string(
"*")) {
77 throw BagException((boost::format(
"GPG key not found for a user %1%") % user.c_str()).str());
80 throw BagException((boost::format(
"gpgme_op_keylist_next returned %1%") % err).str());
83 err = gpgme_op_keylist_end(ctx);
85 throw BagException((boost::format(
"gpgme_op_keylist_end returned %1%") % gpgme_strerror(err)).str());