cpp: Return actual error if revocation fails

* lang/cpp/src/editinteractor.cpp, lang/cpp/src/editinteractor.h
(EditInteractor::parseStatusError): New.
* lang/cpp/src/gpgrevokekeyeditinteractor.cpp
(GpgRevokeKeyEditInteractor::Private::nextState): Handle status
error.
--

With this change the interactor returns a proper error like "Bad
Passphrase" or "Empty Passphrase" instead of an unspecific "General
Error" if a status error occurred.

GnuPG-bug-id: 5904
This commit is contained in:
Ingo Klöcker 2022-04-04 13:15:37 +02:00
parent c965b45bcd
commit db532eca8e
3 changed files with 22 additions and 0 deletions

View File

@ -29,6 +29,7 @@
#include "editinteractor.h"
#include "callbacks.h"
#include "error.h"
#include "util.h"
#include <gpgme.h>
@ -256,6 +257,20 @@ void EditInteractor::setDebugChannel(std::FILE *debug)
d->debug = debug;
}
GpgME::Error EditInteractor::parseStatusError(const char *args)
{
Error err;
const auto fields = split(args, ' ');
if (fields.size() >= 2) {
err = Error{static_cast<unsigned int>(std::stoul(fields[1]))};
} else {
err = Error::fromCode(GPG_ERR_GENERAL);
}
return err;
}
static const char *const status_strings[] = {
"EOF",
/* mkstatus processing starts here */

View File

@ -60,6 +60,9 @@ public:
void setDebugChannel(std::FILE *file);
protected:
Error parseStatusError(const char *args);
private:
class Private;
Private *const d;

View File

@ -116,6 +116,10 @@ unsigned int GpgRevokeKeyEditInteractor::Private::nextState(unsigned int status,
return q->state();
}
if (status == GPGME_STATUS_ERROR) {
err = q->parseStatusError(args);
return ERROR;
}
switch (const auto state = q->state()) {
case START:
if (status == GPGME_STATUS_GET_LINE &&