Blame lang/cpp/src/gpgsetownertrusteditinteractor.cpp

Packit Service 672cf4
/*
Packit Service 672cf4
  gpgsetownertrusteditinteractor.cpp - Edit Interactor to change the expiry time of an OpenPGP key
Packit Service 672cf4
  Copyright (C) 2007 Klarälvdalens Datakonsult AB
Packit Service 672cf4
  2016 Bundesamt für Sicherheit in der Informationstechnik
Packit Service 672cf4
  Software engineering by Intevation GmbH
Packit Service 672cf4
Packit Service 672cf4
  This file is part of GPGME++.
Packit Service 672cf4
Packit Service 672cf4
  GPGME++ is free software; you can redistribute it and/or
Packit Service 672cf4
  modify it under the terms of the GNU Library General Public
Packit Service 672cf4
  License as published by the Free Software Foundation; either
Packit Service 672cf4
  version 2 of the License, or (at your option) any later version.
Packit Service 672cf4
Packit Service 672cf4
  GPGME++ is distributed in the hope that it will be useful,
Packit Service 672cf4
  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 672cf4
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 672cf4
  GNU Library General Public License for more details.
Packit Service 672cf4
Packit Service 672cf4
  You should have received a copy of the GNU Library General Public License
Packit Service 672cf4
  along with GPGME++; see the file COPYING.LIB.  If not, write to the
Packit Service 672cf4
  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Packit Service 672cf4
  Boston, MA 02110-1301, USA.
Packit Service 672cf4
*/
Packit Service 672cf4
Packit Service 672cf4
#ifdef HAVE_CONFIG_H
Packit Service 672cf4
 #include "config.h"
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#include "gpgsetownertrusteditinteractor.h"
Packit Service 672cf4
#include "error.h"
Packit Service 672cf4
Packit Service 672cf4
#include <gpgme.h>
Packit Service 672cf4
Packit Service 672cf4
#include <cstring>
Packit Service 672cf4
Packit Service 672cf4
using std::strcmp;
Packit Service 672cf4
Packit Service 672cf4
// avoid conflict (msvc)
Packit Service 672cf4
#ifdef ERROR
Packit Service 672cf4
# undef ERROR
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
using namespace GpgME;
Packit Service 672cf4
Packit Service 672cf4
GpgSetOwnerTrustEditInteractor::GpgSetOwnerTrustEditInteractor(Key::OwnerTrust ot)
Packit Service 672cf4
    : EditInteractor(),
Packit Service 672cf4
      m_ownertrust(ot)
Packit Service 672cf4
{
Packit Service 672cf4
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgSetOwnerTrustEditInteractor::~GpgSetOwnerTrustEditInteractor() {}
Packit Service 672cf4
Packit Service 672cf4
// work around --enable-final
Packit Service 672cf4
namespace GpgSetOwnerTrustEditInteractor_Private
Packit Service 672cf4
{
Packit Service 672cf4
enum {
Packit Service 672cf4
    START = EditInteractor::StartState,
Packit Service 672cf4
    COMMAND,
Packit Service 672cf4
    VALUE,
Packit Service 672cf4
    REALLY_ULTIMATE,
Packit Service 672cf4
    QUIT,
Packit Service 672cf4
    SAVE,
Packit Service 672cf4
Packit Service 672cf4
    ERROR = EditInteractor::ErrorState
Packit Service 672cf4
};
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
const char *GpgSetOwnerTrustEditInteractor::action(Error &err) const
Packit Service 672cf4
{
Packit Service 672cf4
    static const char truststrings[][2] = { "1", "1", "2", "3", "4", "5" };
Packit Service 672cf4
Packit Service 672cf4
    using namespace GpgSetOwnerTrustEditInteractor_Private;
Packit Service 672cf4
Packit Service 672cf4
    switch (state()) {
Packit Service 672cf4
    case COMMAND:
Packit Service 672cf4
        return "trust";
Packit Service 672cf4
    case VALUE:
Packit Service 672cf4
        return truststrings[m_ownertrust];
Packit Service 672cf4
    case REALLY_ULTIMATE:
Packit Service 672cf4
        return "Y";
Packit Service 672cf4
    case QUIT:
Packit Service 672cf4
        return "quit";
Packit Service 672cf4
    case SAVE:
Packit Service 672cf4
        return "Y";
Packit Service 672cf4
    case START:
Packit Service 672cf4
    case ERROR:
Packit Service 6c01f9
        return 0;
Packit Service 672cf4
    default:
Packit Service 672cf4
        err = Error::fromCode(GPG_ERR_GENERAL);
Packit Service 6c01f9
        return 0;
Packit Service 672cf4
    }
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
unsigned int GpgSetOwnerTrustEditInteractor::nextState(unsigned int status, const char *args, Error &err) const
Packit Service 672cf4
{
Packit Service 672cf4
Packit Service 672cf4
    static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL);
Packit Service 672cf4
    //static const Error INV_TIME_ERROR = Error::fromCode( GPG_ERR_INV_TIME );
Packit Service 672cf4
Packit Service 672cf4
    if (needsNoResponse(status)) {
Packit Service 672cf4
        return state();
Packit Service 672cf4
    }
Packit Service 672cf4
Packit Service 672cf4
    using namespace GpgSetOwnerTrustEditInteractor_Private;
Packit Service 672cf4
Packit Service 672cf4
    switch (state()) {
Packit Service 672cf4
    case START:
Packit Service 672cf4
        if (status == GPGME_STATUS_GET_LINE &&
Packit Service 672cf4
                strcmp(args, "keyedit.prompt") == 0) {
Packit Service 672cf4
            return COMMAND;
Packit Service 672cf4
        }
Packit Service 672cf4
        err = GENERAL_ERROR;
Packit Service 672cf4
        return ERROR;
Packit Service 672cf4
    case COMMAND:
Packit Service 672cf4
        if (status == GPGME_STATUS_GET_LINE &&
Packit Service 672cf4
                strcmp(args, "edit_ownertrust.value") == 0) {
Packit Service 672cf4
            return VALUE;
Packit Service 672cf4
        }
Packit Service 672cf4
        err = GENERAL_ERROR;
Packit Service 672cf4
        return ERROR;
Packit Service 672cf4
    case VALUE:
Packit Service 672cf4
        if (status == GPGME_STATUS_GET_LINE &&
Packit Service 672cf4
                strcmp(args, "keyedit.prompt") == 0) {
Packit Service 672cf4
            return QUIT;
Packit Service 672cf4
        } else if (status == GPGME_STATUS_GET_BOOL &&
Packit Service 672cf4
                   strcmp(args, "edit_ownertrust.set_ultimate.okay") == 0) {
Packit Service 672cf4
            return REALLY_ULTIMATE;
Packit Service 672cf4
        }
Packit Service 672cf4
        err = GENERAL_ERROR;
Packit Service 672cf4
        return ERROR;
Packit Service 672cf4
    case REALLY_ULTIMATE:
Packit Service 672cf4
        if (status == GPGME_STATUS_GET_LINE &&
Packit Service 672cf4
                strcmp(args, "keyedit.prompt") == 0) {
Packit Service 672cf4
            return QUIT;
Packit Service 672cf4
        }
Packit Service 672cf4
        err = GENERAL_ERROR;
Packit Service 672cf4
        return ERROR;
Packit Service 672cf4
    case QUIT:
Packit Service 672cf4
        if (status == GPGME_STATUS_GET_BOOL &&
Packit Service 672cf4
                strcmp(args, "keyedit.save.okay") == 0) {
Packit Service 672cf4
            return SAVE;
Packit Service 672cf4
        }
Packit Service 672cf4
        err = GENERAL_ERROR;
Packit Service 672cf4
        return ERROR;
Packit Service 672cf4
    case ERROR:
Packit Service 672cf4
        if (status == GPGME_STATUS_GET_LINE &&
Packit Service 672cf4
                strcmp(args, "keyedit.prompt") == 0) {
Packit Service 672cf4
            return QUIT;
Packit Service 672cf4
        }
Packit Service 672cf4
        err = lastError();
Packit Service 672cf4
        return ERROR;
Packit Service 672cf4
    default:
Packit Service 672cf4
        err = GENERAL_ERROR;
Packit Service 672cf4
        return ERROR;
Packit Service 672cf4
    };
Packit Service 672cf4
}