mirror of
https://github.com/AGWA/git-crypt.git
synced 2025-12-09 06:10:33 -08:00
Read gpg program from git config gpg.program ; ported from fork by alanrossmachinery
Modified-By: Andrew Ayer <agwa@andrewayer.name> * Make whitespace conform to project conventions Closes #89 Closes #65
This commit is contained in:
@@ -254,7 +254,7 @@ static std::string get_internal_key_path (const char* key_name)
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string get_git_config (const std::string& name)
|
std::string get_git_config (const std::string& name)
|
||||||
{
|
{
|
||||||
// git config --get
|
// git config --get
|
||||||
std::vector<std::string> command;
|
std::vector<std::string> command;
|
||||||
|
|||||||
@@ -70,4 +70,7 @@ void help_migrate_key (std::ostream&);
|
|||||||
void help_refresh (std::ostream&);
|
void help_refresh (std::ostream&);
|
||||||
void help_status (std::ostream&);
|
void help_status (std::ostream&);
|
||||||
|
|
||||||
|
// other
|
||||||
|
std::string get_git_config (const std::string& name);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
20
gpg.cpp
20
gpg.cpp
@@ -30,8 +30,18 @@
|
|||||||
|
|
||||||
#include "gpg.hpp"
|
#include "gpg.hpp"
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
|
#include "commands.hpp"
|
||||||
#include <sstream>
|
#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)
|
static std::string gpg_nth_column (const std::string& line, unsigned int col)
|
||||||
{
|
{
|
||||||
std::string::size_type pos = 0;
|
std::string::size_type pos = 0;
|
||||||
@@ -62,7 +72,7 @@ std::string gpg_get_uid (const std::string& fingerprint)
|
|||||||
{
|
{
|
||||||
// gpg --batch --with-colons --fixed-list-mode --list-keys 0x7A399B2DB06D039020CD1CE1D0F3702D61489532
|
// gpg --batch --with-colons --fixed-list-mode --list-keys 0x7A399B2DB06D039020CD1CE1D0F3702D61489532
|
||||||
std::vector<std::string> command;
|
std::vector<std::string> command;
|
||||||
command.push_back("gpg");
|
command.push_back(gpg_get_executable());
|
||||||
command.push_back("--batch");
|
command.push_back("--batch");
|
||||||
command.push_back("--with-colons");
|
command.push_back("--with-colons");
|
||||||
command.push_back("--fixed-list-mode");
|
command.push_back("--fixed-list-mode");
|
||||||
@@ -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
|
// gpg --batch --with-colons --fingerprint --list-keys jsmith@example.com
|
||||||
std::vector<std::string> command;
|
std::vector<std::string> command;
|
||||||
command.push_back("gpg");
|
command.push_back(gpg_get_executable());
|
||||||
command.push_back("--batch");
|
command.push_back("--batch");
|
||||||
command.push_back("--with-colons");
|
command.push_back("--with-colons");
|
||||||
command.push_back("--fingerprint");
|
command.push_back("--fingerprint");
|
||||||
@@ -125,7 +135,7 @@ std::vector<std::string> gpg_list_secret_keys ()
|
|||||||
{
|
{
|
||||||
// gpg --batch --with-colons --list-secret-keys --fingerprint
|
// gpg --batch --with-colons --list-secret-keys --fingerprint
|
||||||
std::vector<std::string> command;
|
std::vector<std::string> command;
|
||||||
command.push_back("gpg");
|
command.push_back(gpg_get_executable());
|
||||||
command.push_back("--batch");
|
command.push_back("--batch");
|
||||||
command.push_back("--with-colons");
|
command.push_back("--with-colons");
|
||||||
command.push_back("--list-secret-keys");
|
command.push_back("--list-secret-keys");
|
||||||
@@ -154,7 +164,7 @@ void gpg_encrypt_to_file (const std::string& filename, const std::string& recipi
|
|||||||
{
|
{
|
||||||
// gpg --batch -o FILENAME -r RECIPIENT -e
|
// gpg --batch -o FILENAME -r RECIPIENT -e
|
||||||
std::vector<std::string> command;
|
std::vector<std::string> command;
|
||||||
command.push_back("gpg");
|
command.push_back(gpg_get_executable());
|
||||||
command.push_back("--batch");
|
command.push_back("--batch");
|
||||||
if (key_is_trusted) {
|
if (key_is_trusted) {
|
||||||
command.push_back("--trust-model");
|
command.push_back("--trust-model");
|
||||||
@@ -174,7 +184,7 @@ void gpg_decrypt_from_file (const std::string& filename, std::ostream& output)
|
|||||||
{
|
{
|
||||||
// gpg -q -d FILENAME
|
// gpg -q -d FILENAME
|
||||||
std::vector<std::string> command;
|
std::vector<std::string> command;
|
||||||
command.push_back("gpg");
|
command.push_back(gpg_get_executable());
|
||||||
command.push_back("-q");
|
command.push_back("-q");
|
||||||
command.push_back("-d");
|
command.push_back("-d");
|
||||||
command.push_back(filename);
|
command.push_back(filename);
|
||||||
|
|||||||
Reference in New Issue
Block a user