cpp: Support new keylist modes

* lang/cpp/src/global.h (ForceExtern, LocateExternal, KeyListModeMask):
New.
* lang/cpp/src/context.cpp (operator<<): Add check.
* lang/cpp/src/util.h (gpgme_keylist_mode_t,
convert_from_gpgme_keylist_mode_t): Handle ForceExtern.
* lang/cpp/tests/run-getkey.cpp (show_usage, main): Add arguments
--force-extern and --locate-external.
* lang/cpp/tests/run-keylist.cpp (show_usage, main): Ditto.
--

GnuPG-bug-id: 5951
This commit is contained in:
Ingo Klöcker 2022-04-27 17:21:04 +02:00
parent aff9aaac68
commit dea872f21f
6 changed files with 37 additions and 13 deletions

3
NEWS
View File

@ -14,6 +14,9 @@ Noteworthy changes in version 1.17.2 (unreleased)
cpp: RevocationReason NEW. cpp: RevocationReason NEW.
cpp: GpgRevokeKeyEditInteractor NEW. cpp: GpgRevokeKeyEditInteractor NEW.
cpp: Result::setError NEW. cpp: Result::setError NEW.
cpp: KeyListMode::ForceExtern NEW.
cpp: KeyListMode::LocateExternal NEW.
cpp: KeyListMode::KeyListModeMask NEW.
qt: RevokeKeyJob NEW. qt: RevokeKeyJob NEW.
qt: Protocol::revokeKeyJob NEW. qt: Protocol::revokeKeyJob NEW.

View File

@ -1849,6 +1849,7 @@ std::ostream &operator<<(std::ostream &os, KeyListMode mode)
CHECK(WithTofu); CHECK(WithTofu);
CHECK(WithKeygrip); CHECK(WithKeygrip);
CHECK(WithSecret); CHECK(WithSecret);
CHECK(ForceExtern);
#undef CHECK #undef CHECK
return os << ')'; return os << ')';
} }

View File

@ -60,14 +60,18 @@ enum Engine { GpgEngine, GpgSMEngine, GpgConfEngine, UnknownEngine, AssuanEngine
enum KeyListMode { enum KeyListMode {
Local = 0x1, Local = 0x1,
Extern = 0x2, Extern = 0x2,
Locate = 0x3, Locate = Local|Extern,
Signatures = 0x4, Signatures = 0x4,
SignatureNotations = 0x8, SignatureNotations = 0x8,
Validate = 0x10, Validate = 0x10,
Ephemeral = 0x20, Ephemeral = 0x20,
WithTofu = 0x40, WithTofu = 0x40,
WithKeygrip = 0x80, WithKeygrip = 0x80,
WithSecret = 0x100 WithSecret = 0x100,
ForceExtern = 0x200,
LocateExternal = Locate|ForceExtern,
KeyListModeMask = 0x3ff
}; };
enum SignatureMode { NormalSignatureMode, Detached, Clearsigned }; enum SignatureMode { NormalSignatureMode, Detached, Clearsigned };

View File

@ -89,19 +89,15 @@ static inline gpgme_keylist_mode_t add_to_gpgme_keylist_mode_t(unsigned int oldm
if (newmodes & GpgME::WithSecret) { if (newmodes & GpgME::WithSecret) {
oldmode |= GPGME_KEYLIST_MODE_WITH_SECRET; oldmode |= GPGME_KEYLIST_MODE_WITH_SECRET;
} }
if (newmodes & GpgME::ForceExtern) {
oldmode |= GPGME_KEYLIST_MODE_FORCE_EXTERN;
}
#ifndef NDEBUG #ifndef NDEBUG
if (newmodes & ~(GpgME::Local | if (newmodes & ~(GpgME::KeyListModeMask)) {
GpgME::Extern |
GpgME::Signatures |
GpgME::SignatureNotations |
GpgME::Validate |
GpgME::Ephemeral |
GpgME::WithTofu |
GpgME::WithKeygrip |
GpgME::WithSecret)) {
//std::cerr << "GpgME::Context: keylist mode must be one of Local, " //std::cerr << "GpgME::Context: keylist mode must be one of Local, "
//"Extern, Signatures, SignatureNotations, Validate, Ephemeral, WithTofu, " //"Extern, Signatures, SignatureNotations, Validate, Ephemeral, WithTofu, "
//"WithKeygrip, WithSecret, or a combination thereof!" << std::endl; //"WithKeygrip, WithSecret, ForceExtern, or a combination thereof!"
//<< std::endl;
} }
#endif #endif
return static_cast<gpgme_keylist_mode_t>(oldmode); return static_cast<gpgme_keylist_mode_t>(oldmode);
@ -137,6 +133,9 @@ static inline unsigned int convert_from_gpgme_keylist_mode_t(unsigned int mode)
if (mode & GPGME_KEYLIST_MODE_VALIDATE) { if (mode & GPGME_KEYLIST_MODE_VALIDATE) {
result |= GpgME::Validate; result |= GpgME::Validate;
} }
if (mode & GPGME_KEYLIST_MODE_FORCE_EXTERN) {
result |= GpgME::ForceExtern;
}
#ifndef NDEBUG #ifndef NDEBUG
if (mode & ~(GPGME_KEYLIST_MODE_LOCAL | if (mode & ~(GPGME_KEYLIST_MODE_LOCAL |
GPGME_KEYLIST_MODE_EXTERN | GPGME_KEYLIST_MODE_EXTERN |
@ -146,7 +145,8 @@ static inline unsigned int convert_from_gpgme_keylist_mode_t(unsigned int mode)
GPGME_KEYLIST_MODE_WITH_TOFU | GPGME_KEYLIST_MODE_WITH_TOFU |
GPGME_KEYLIST_MODE_WITH_KEYGRIP | GPGME_KEYLIST_MODE_WITH_KEYGRIP |
GPGME_KEYLIST_MODE_EPHEMERAL | GPGME_KEYLIST_MODE_EPHEMERAL |
GPGME_KEYLIST_MODE_VALIDATE)) { GPGME_KEYLIST_MODE_VALIDATE |
GPGME_KEYLIST_MODE_FORCE_EXTERN)) {
//std::cerr << "GpgME: WARNING: gpgme_get_keylist_mode() returned an unknown flag!" << std::endl; //std::cerr << "GpgME: WARNING: gpgme_get_keylist_mode() returned an unknown flag!" << std::endl;
} }
#endif // NDEBUG #endif // NDEBUG

View File

@ -60,6 +60,8 @@ show_usage (int ex)
" --ephemeral use GPGME_KEYLIST_MODE_EPHEMERAL\n" " --ephemeral use GPGME_KEYLIST_MODE_EPHEMERAL\n"
" --validate use GPGME_KEYLIST_MODE_VALIDATE\n" " --validate use GPGME_KEYLIST_MODE_VALIDATE\n"
" --locate use GPGME_KEYLIST_MODE_LOCATE\n" " --locate use GPGME_KEYLIST_MODE_LOCATE\n"
" --force-extern use GPGME_KEYLIST_MODE_FORCE_EXTERN\n"
" --locate-external use GPGME_KEYLIST_MODE_LOCATE_EXTERNAL\n"
, stderr); , stderr);
exit (ex); exit (ex);
} }
@ -116,6 +118,12 @@ main (int argc, char **argv)
} else if (!strcmp (*argv, "--locate")) { } else if (!strcmp (*argv, "--locate")) {
argc--; argv++; argc--; argv++;
mode |= KeyListMode::Locate; mode |= KeyListMode::Locate;
} else if (!strcmp (*argv, "--force-extern")) {
argc--; argv++;
mode |= KeyListMode::ForceExtern;
} else if (!strcmp (*argv, "--locate-external")) {
argc--; argv++;
mode |= KeyListMode::LocateExternal;
} else if (!strncmp (*argv, "--", 2)) { } else if (!strncmp (*argv, "--", 2)) {
show_usage (1); show_usage (1);
} }

View File

@ -61,6 +61,8 @@ show_usage (int ex)
" --ephemeral use GPGME_KEYLIST_MODE_EPHEMERAL\n" " --ephemeral use GPGME_KEYLIST_MODE_EPHEMERAL\n"
" --validate use GPGME_KEYLIST_MODE_VALIDATE\n" " --validate use GPGME_KEYLIST_MODE_VALIDATE\n"
" --locate use GPGME_KEYLIST_MODE_LOCATE\n" " --locate use GPGME_KEYLIST_MODE_LOCATE\n"
" --force-extern use GPGME_KEYLIST_MODE_FORCE_EXTERN\n"
" --locate-external use GPGME_KEYLIST_MODE_LOCATE_EXTERNAL\n"
, stderr); , stderr);
exit (ex); exit (ex);
} }
@ -117,6 +119,12 @@ main (int argc, char **argv)
} else if (!strcmp (*argv, "--locate")) { } else if (!strcmp (*argv, "--locate")) {
argc--; argv++; argc--; argv++;
mode |= KeyListMode::Locate; mode |= KeyListMode::Locate;
} else if (!strcmp (*argv, "--force-extern")) {
argc--; argv++;
mode |= KeyListMode::ForceExtern;
} else if (!strcmp (*argv, "--locate-external")) {
argc--; argv++;
mode |= KeyListMode::LocateExternal;
} else if (!strncmp (*argv, "--", 2)) { } else if (!strncmp (*argv, "--", 2)) {
show_usage (1); show_usage (1);
} }