Skip to content

Commit

Permalink
Read gpg program from git config gpg.program ; ported from fork by al…
Browse files Browse the repository at this point in the history
…anrossmachinery

Modified-By: Andrew Ayer <agwa@andrewayer.name>

  * Make whitespace conform to project conventions

Closes #89
Closes #65
  • Loading branch information
AGWA committed Sep 10, 2017
1 parent 934914c commit 101b738
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static std::string get_internal_key_path (const char* key_name)
return path;
}

static std::string get_git_config (const std::string& name)
std::string get_git_config (const std::string& name)
{
// git config --get
std::vector<std::string> command;
Expand Down
3 changes: 3 additions & 0 deletions commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ void help_migrate_key (std::ostream&);
void help_refresh (std::ostream&);
void help_status (std::ostream&);

// other
std::string get_git_config (const std::string& name);

#endif
20 changes: 15 additions & 5 deletions gpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,18 @@

#include "gpg.hpp"
#include "util.hpp"
#include "commands.hpp"
#include <sstream>

static std::string gpg_get_executable()
{
std::string gpgbin = "gpg";
try {
gpgbin = get_git_config("gpg.program");
} catch (...) {
}
return gpgbin;
}
static std::string gpg_nth_column (const std::string& line, unsigned int col)
{
std::string::size_type pos = 0;
Expand Down Expand Up @@ -62,7 +72,7 @@ std::string gpg_get_uid (const std::string& fingerprint)
{
// gpg --batch --with-colons --fixed-list-mode --list-keys 0x7A399B2DB06D039020CD1CE1D0F3702D61489532
std::vector<std::string> command;
command.push_back("gpg");
command.push_back(gpg_get_executable());
command.push_back("--batch");
command.push_back("--with-colons");
command.push_back("--fixed-list-mode");
Expand Down Expand Up @@ -94,7 +104,7 @@ std::vector<std::string> gpg_lookup_key (const std::string& query)

// gpg --batch --with-colons --fingerprint --list-keys jsmith@example.com
std::vector<std::string> command;
command.push_back("gpg");
command.push_back(gpg_get_executable());
command.push_back("--batch");
command.push_back("--with-colons");
command.push_back("--fingerprint");
Expand Down Expand Up @@ -125,7 +135,7 @@ std::vector<std::string> gpg_list_secret_keys ()
{
// gpg --batch --with-colons --list-secret-keys --fingerprint
std::vector<std::string> command;
command.push_back("gpg");
command.push_back(gpg_get_executable());
command.push_back("--batch");
command.push_back("--with-colons");
command.push_back("--list-secret-keys");
Expand Down Expand Up @@ -154,7 +164,7 @@ void gpg_encrypt_to_file (const std::string& filename, const std::string& recipi
{
// gpg --batch -o FILENAME -r RECIPIENT -e
std::vector<std::string> command;
command.push_back("gpg");
command.push_back(gpg_get_executable());
command.push_back("--batch");
if (key_is_trusted) {
command.push_back("--trust-model");
Expand All @@ -174,7 +184,7 @@ void gpg_decrypt_from_file (const std::string& filename, std::ostream& output)
{
// gpg -q -d FILENAME
std::vector<std::string> command;
command.push_back("gpg");
command.push_back(gpg_get_executable());
command.push_back("-q");
command.push_back("-d");
command.push_back(filename);
Expand Down

0 comments on commit 101b738

Please sign in to comment.