30
30
31
31
#include " gpg.hpp"
32
32
#include " util.hpp"
33
+ #include " commands.hpp"
33
34
#include < sstream>
34
35
36
+ static std::string gpg_get_executable ()
37
+ {
38
+ std::string gpgbin = " gpg" ;
39
+ try {
40
+ gpgbin = get_git_config (" gpg.program" );
41
+ } catch (...) {
42
+ }
43
+ return gpgbin;
44
+ }
35
45
static std::string gpg_nth_column (const std::string& line, unsigned int col)
36
46
{
37
47
std::string::size_type pos = 0 ;
@@ -62,7 +72,7 @@ std::string gpg_get_uid (const std::string& fingerprint)
62
72
{
63
73
// gpg --batch --with-colons --fixed-list-mode --list-keys 0x7A399B2DB06D039020CD1CE1D0F3702D61489532
64
74
std::vector<std::string> command;
65
- command.push_back (" gpg " );
75
+ command.push_back (gpg_get_executable () );
66
76
command.push_back (" --batch" );
67
77
command.push_back (" --with-colons" );
68
78
command.push_back (" --fixed-list-mode" );
@@ -94,7 +104,7 @@ std::vector<std::string> gpg_lookup_key (const std::string& query)
94
104
95
105
// gpg --batch --with-colons --fingerprint --list-keys jsmith@example.com
96
106
std::vector<std::string> command;
97
- command.push_back (" gpg " );
107
+ command.push_back (gpg_get_executable () );
98
108
command.push_back (" --batch" );
99
109
command.push_back (" --with-colons" );
100
110
command.push_back (" --fingerprint" );
@@ -125,7 +135,7 @@ std::vector<std::string> gpg_list_secret_keys ()
125
135
{
126
136
// gpg --batch --with-colons --list-secret-keys --fingerprint
127
137
std::vector<std::string> command;
128
- command.push_back (" gpg " );
138
+ command.push_back (gpg_get_executable () );
129
139
command.push_back (" --batch" );
130
140
command.push_back (" --with-colons" );
131
141
command.push_back (" --list-secret-keys" );
@@ -154,7 +164,7 @@ void gpg_encrypt_to_file (const std::string& filename, const std::string& recipi
154
164
{
155
165
// gpg --batch -o FILENAME -r RECIPIENT -e
156
166
std::vector<std::string> command;
157
- command.push_back (" gpg " );
167
+ command.push_back (gpg_get_executable () );
158
168
command.push_back (" --batch" );
159
169
if (key_is_trusted) {
160
170
command.push_back (" --trust-model" );
@@ -174,7 +184,7 @@ void gpg_decrypt_from_file (const std::string& filename, std::ostream& output)
174
184
{
175
185
// gpg -q -d FILENAME
176
186
std::vector<std::string> command;
177
- command.push_back (" gpg " );
187
+ command.push_back (gpg_get_executable () );
178
188
command.push_back (" -q" );
179
189
command.push_back (" -d" );
180
190
command.push_back (filename);
0 commit comments