JSON-18 #comment Add function getGpgEnvironment() that returns an object with 3 optional strings (which each might be null).
parent
c352ebb132
commit
8a74086b30
@ -0,0 +1,45 @@
|
||||
#include "gpg_environment.hh"
|
||||
#include "function_map.hh"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <pEp/message_api.h> // for get_binary_path()
|
||||
|
||||
GpgEnvironment getGpgEnvironment()
|
||||
{
|
||||
GpgEnvironment ge{};
|
||||
|
||||
const char* gpg_path = nullptr;
|
||||
const auto status = get_binary_path( PEP_crypt_OpenPGP, &gpg_path);
|
||||
if(status == PEP_STATUS_OK && gpg_path)
|
||||
{
|
||||
ge.gnupg_path = std::string(gpg_path);
|
||||
}
|
||||
|
||||
const char* home = std::getenv("GNUPGHOME");
|
||||
if(home)
|
||||
{
|
||||
ge.gnupg_home = std::string(home);
|
||||
}
|
||||
|
||||
const char* ai = std::getenv("GPG_AGENT_INFO");
|
||||
if(home)
|
||||
{
|
||||
ge.gpg_agent_info = std::string(ai);
|
||||
}
|
||||
|
||||
return ge;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
js::Value to_json<GpgEnvironment>(const GpgEnvironment& ge)
|
||||
{
|
||||
js::Object obj;
|
||||
obj.emplace_back("gnupg_path", (ge.gnupg_path ? ge.gnupg_path.get() : js::Value{}) );
|
||||
obj.emplace_back("gnupg_home", (ge.gnupg_home ? ge.gnupg_home.get() : js::Value{}) );
|
||||
obj.emplace_back("gpg_agent_info", (ge.gpg_agent_info ? ge.gpg_agent_info.get() : js::Value{}) );
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<>
|
||||
js::Value Type2String<GpgEnvironment>::get() { return "GpgEnvironment"; }
|
@ -0,0 +1,16 @@
|
||||
#ifndef JSON_GPG_ENVIRONMENT_HH
|
||||
#define JSON_GPG_ENVIRONMENT_HH
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <string>
|
||||
|
||||
struct GpgEnvironment
|
||||
{
|
||||
boost::optional<std::string> gnupg_path; // filled by pEpEngine's gnu_gpg_path()
|
||||
boost::optional<std::string> gnupg_home; // filled by getenv("GNUPGHOME")
|
||||
boost::optional<std::string> gpg_agent_info; // filled by getenv("GPG_AGENT_INFO")
|
||||
};
|
||||
|
||||
GpgEnvironment getGpgEnvironment();
|
||||
|
||||
#endif
|
Loading…
Reference in new issue