given a key fingerprint, return the key's UID (e.g. "John Smith ")
| 63 | |
| 64 | // given a key fingerprint, return the key's UID (e.g. "John Smith <jsmith@example.com>") |
| 65 | std::string gpg_get_uid (const std::string& fingerprint) |
| 66 | { |
| 67 | // gpg --batch --with-colons --fixed-list-mode --list-keys 0x7A399B2DB06D039020CD1CE1D0F3702D61489532 |
| 68 | std::vector<std::string> command; |
| 69 | command.push_back(gpg_get_executable()); |
| 70 | command.push_back("--batch"); |
| 71 | command.push_back("--with-colons"); |
| 72 | command.push_back("--fixed-list-mode"); |
| 73 | command.push_back("--list-keys"); |
| 74 | command.push_back("0x" + fingerprint); |
| 75 | std::stringstream command_output; |
| 76 | if (!successful_exit(exec_command(command, command_output))) { |
| 77 | // This could happen if the keyring does not contain a public key with this fingerprint |
| 78 | return ""; |
| 79 | } |
| 80 | |
| 81 | while (command_output.peek() != -1) { |
| 82 | std::string line; |
| 83 | std::getline(command_output, line); |
| 84 | if (line.substr(0, 4) == "uid:") { |
| 85 | // uid:u::::1395975462::AB97D6E3E5D8789988CA55E5F77D9E7397D05229::John Smith <jsmith@example.com>: |
| 86 | // want the 9th column (counting from 0) |
| 87 | return gpg_nth_column(line, 9); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | return ""; |
| 92 | } |
| 93 | |
| 94 | // return a list of fingerprints of public keys matching the given search query (such as jsmith@example.com) |
| 95 | std::vector<std::string> gpg_lookup_key (const std::string& query) |
no test coverage detected