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

Generated by: LCOV version 1.11