MCPcopy Create free account
hub / github.com/AGWA/git-crypt / gpg_lookup_key

Function gpg_lookup_key

gpg.cpp:95–126  ·  view source on GitHub ↗

return a list of fingerprints of public keys matching the given search query (such as jsmith@example.com)

Source from the content-addressed store, hash-verified

93
94// return a list of fingerprints of public keys matching the given search query (such as jsmith@example.com)
95std::vector<std::string> gpg_lookup_key (const std::string& query)
96{
97 std::vector<std::string> fingerprints;
98
99 // gpg --batch --with-colons --fingerprint --list-keys jsmith@example.com
100 std::vector<std::string> command;
101 command.push_back(gpg_get_executable());
102 command.push_back("--batch");
103 command.push_back("--with-colons");
104 command.push_back("--fingerprint");
105 command.push_back("--list-keys");
106 command.push_back(query);
107 std::stringstream command_output;
108 if (successful_exit(exec_command(command, command_output))) {
109 bool is_pubkey = false;
110 while (command_output.peek() != -1) {
111 std::string line;
112 std::getline(command_output, line);
113 if (line.substr(0, 4) == "pub:") {
114 is_pubkey = true;
115 } else if (line.substr(0, 4) == "sub:") {
116 is_pubkey = false;
117 } else if (is_pubkey && line.substr(0, 4) == "fpr:") {
118 // fpr:::::::::7A399B2DB06D039020CD1CE1D0F3702D61489532:
119 // want the 9th column (counting from 0)
120 fingerprints.push_back(gpg_nth_column(line, 9));
121 }
122 }
123 }
124
125 return fingerprints;
126}
127
128std::vector<std::string> gpg_list_secret_keys ()
129{

Callers 1

add_gpg_userFunction · 0.85

Calls 4

gpg_get_executableFunction · 0.85
successful_exitFunction · 0.85
exec_commandFunction · 0.85
gpg_nth_columnFunction · 0.85

Tested by

no test coverage detected