LCOV - code coverage report
Current view: top level - lang/cpp/src - gpgsetexpirytimeeditinteractor.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 50 0.0 %
Date: 2018-11-14 16:53:58 Functions: 0 5 0.0 %

          Line data    Source code
       1             : /*
       2             :   gpgsetexpirytimeeditinteractor.cpp - Edit Interactor to change the expiry time of an OpenPGP key
       3             :   Copyright (C) 2007 Klarälvdalens Datakonsult AB
       4             :   2016 Bundesamt für Sicherheit in der Informationstechnik
       5             :   Software engineering by Intevation GmbH
       6             : 
       7             :   This file is part of GPGME++.
       8             : 
       9             :   GPGME++ is free software; you can redistribute it and/or
      10             :   modify it under the terms of the GNU Library General Public
      11             :   License as published by the Free Software Foundation; either
      12             :   version 2 of the License, or (at your option) any later version.
      13             : 
      14             :   GPGME++ is distributed in the hope that it will be useful,
      15             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :   GNU Library General Public License for more details.
      18             : 
      19             :   You should have received a copy of the GNU Library General Public License
      20             :   along with GPGME++; see the file COPYING.LIB.  If not, write to the
      21             :   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
      22             :   Boston, MA 02110-1301, USA.
      23             : */
      24             : 
      25             : #ifdef HAVE_CONFIG_H
      26             :  #include "config.h"
      27             : #endif
      28             : 
      29             : #include "gpgsetexpirytimeeditinteractor.h"
      30             : #include "error.h"
      31             : 
      32             : #include <gpgme.h>
      33             : 
      34             : #include <cstring>
      35             : 
      36             : using std::strcmp;
      37             : 
      38             : // avoid conflict (msvc)
      39             : #ifdef ERROR
      40             : # undef ERROR
      41             : #endif
      42             : 
      43             : using namespace GpgME;
      44             : 
      45           0 : GpgSetExpiryTimeEditInteractor::GpgSetExpiryTimeEditInteractor(const std::string &t)
      46             :     : EditInteractor(),
      47           0 :       m_strtime(t)
      48             : {
      49             : 
      50           0 : }
      51             : 
      52           0 : GpgSetExpiryTimeEditInteractor::~GpgSetExpiryTimeEditInteractor() {}
      53             : 
      54             : // work around --enable-final
      55             : namespace GpgSetExpiryTimeEditInteractor_Private
      56             : {
      57             : enum {
      58             :     START = EditInteractor::StartState,
      59             :     COMMAND,
      60             :     DATE,
      61             :     QUIT,
      62             :     SAVE,
      63             : 
      64             :     ERROR = EditInteractor::ErrorState
      65             : };
      66             : }
      67             : 
      68           0 : const char *GpgSetExpiryTimeEditInteractor::action(Error &err) const
      69             : {
      70             : 
      71             :     using namespace GpgSetExpiryTimeEditInteractor_Private;
      72             : 
      73           0 :     switch (state()) {
      74             :     case COMMAND:
      75           0 :         return "expire";
      76             :     case DATE:
      77           0 :         return m_strtime.c_str();
      78             :     case QUIT:
      79           0 :         return "quit";
      80             :     case SAVE:
      81           0 :         return "Y";
      82             :     case START:
      83             :     case ERROR:
      84           0 :         return 0;
      85             :     default:
      86           0 :         err = Error::fromCode(GPG_ERR_GENERAL);
      87           0 :         return 0;
      88             :     }
      89             : }
      90             : 
      91           0 : unsigned int GpgSetExpiryTimeEditInteractor::nextState(unsigned int status, const char *args, Error &err) const
      92             : {
      93             : 
      94           0 :     static const Error GENERAL_ERROR  = Error::fromCode(GPG_ERR_GENERAL);
      95           0 :     static const Error INV_TIME_ERROR = Error::fromCode(GPG_ERR_INV_TIME);
      96             : 
      97           0 :     if (needsNoResponse(status)) {
      98           0 :         return state();
      99             :     }
     100             : 
     101             :     using namespace GpgSetExpiryTimeEditInteractor_Private;
     102             : 
     103           0 :     switch (state()) {
     104             :     case START:
     105           0 :         if (status == GPGME_STATUS_GET_LINE &&
     106           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     107           0 :             return COMMAND;
     108             :         }
     109           0 :         err = GENERAL_ERROR;
     110           0 :         return ERROR;
     111             :     case COMMAND:
     112           0 :         if (status == GPGME_STATUS_GET_LINE &&
     113           0 :                 strcmp(args, "keygen.valid") == 0) {
     114           0 :             return DATE;
     115             :         }
     116           0 :         err = GENERAL_ERROR;
     117           0 :         return ERROR;
     118             :     case DATE:
     119           0 :         if (status == GPGME_STATUS_GET_LINE &&
     120           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     121           0 :             return QUIT;
     122           0 :         } else if (status == GPGME_STATUS_GET_LINE &&
     123           0 :                    strcmp(args, "keygen.valid")) {
     124           0 :             err = INV_TIME_ERROR;
     125           0 :             return ERROR;
     126             :         }
     127           0 :         err = GENERAL_ERROR;
     128           0 :         return ERROR;
     129             :     case QUIT:
     130           0 :         if (status == GPGME_STATUS_GET_BOOL &&
     131           0 :                 strcmp(args, "keyedit.save.okay") == 0) {
     132           0 :             return SAVE;
     133             :         }
     134           0 :         err = GENERAL_ERROR;
     135           0 :         return ERROR;
     136             :     case ERROR:
     137           0 :         if (status == GPGME_STATUS_GET_LINE &&
     138           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     139           0 :             return QUIT;
     140             :         }
     141           0 :         err = lastError();
     142           0 :         return ERROR;
     143             :     default:
     144           0 :         err = GENERAL_ERROR;
     145           0 :         return ERROR;
     146             :     }
     147             : }

Generated by: LCOV version 1.13