LCOV - code coverage report
Current view: top level - lang/cpp/src - gpgadduserideditinteractor.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 78 0.0 %
Date: 2018-11-15 08:49:49 Functions: 0 8 0.0 %

          Line data    Source code
       1             : /*
       2             :   gpgadduserideditinteractor.cpp - Edit Interactor to add a new UID to an OpenPGP key
       3             :   Copyright (C) 2008 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 "gpgadduserideditinteractor.h"
      30             : 
      31             : #include "error.h"
      32             : 
      33             : #include <gpgme.h>
      34             : 
      35             : #include <cstring>
      36             : 
      37             : using std::strcmp;
      38             : 
      39             : // avoid conflict (msvc)
      40             : #ifdef ERROR
      41             : # undef ERROR
      42             : #endif
      43             : 
      44             : using namespace GpgME;
      45             : 
      46           0 : GpgAddUserIDEditInteractor::GpgAddUserIDEditInteractor()
      47             :     : EditInteractor(),
      48             :       m_name(),
      49             :       m_email(),
      50           0 :       m_comment()
      51             : {
      52             : 
      53           0 : }
      54             : 
      55           0 : GpgAddUserIDEditInteractor::~GpgAddUserIDEditInteractor() {}
      56             : 
      57           0 : void GpgAddUserIDEditInteractor::setNameUtf8(const std::string &name)
      58             : {
      59           0 :     m_name = name;
      60           0 : }
      61             : 
      62           0 : void GpgAddUserIDEditInteractor::setEmailUtf8(const std::string &email)
      63             : {
      64           0 :     m_email = email;
      65           0 : }
      66             : 
      67           0 : void GpgAddUserIDEditInteractor::setCommentUtf8(const std::string &comment)
      68             : {
      69           0 :     m_comment = comment;
      70           0 : }
      71             : 
      72             : // work around --enable-final
      73             : namespace GpgAddUserIDEditInteractor_Private
      74             : {
      75             : enum {
      76             :     START = EditInteractor::StartState,
      77             :     COMMAND,
      78             :     NAME,
      79             :     EMAIL,
      80             :     COMMENT,
      81             :     QUIT,
      82             :     SAVE,
      83             : 
      84             :     ERROR = EditInteractor::ErrorState
      85             : };
      86             : }
      87             : 
      88           0 : const char *GpgAddUserIDEditInteractor::action(Error &err) const
      89             : {
      90             : 
      91             :     using namespace GpgAddUserIDEditInteractor_Private;
      92             : 
      93           0 :     switch (state()) {
      94             :     case COMMAND:
      95           0 :         return "adduid";
      96             :     case NAME:
      97           0 :         return m_name.c_str();
      98             :     case EMAIL:
      99           0 :         return m_email.c_str();
     100             :     case COMMENT:
     101           0 :         return m_comment.c_str();
     102             :     case QUIT:
     103           0 :         return "quit";
     104             :     case SAVE:
     105           0 :         return "Y";
     106             :     case START:
     107             :     case ERROR:
     108           0 :         return 0;
     109             :     default:
     110           0 :         err = Error::fromCode(GPG_ERR_GENERAL);
     111           0 :         return 0;
     112             :     }
     113             : }
     114             : 
     115           0 : unsigned int GpgAddUserIDEditInteractor::nextState(unsigned int status, const char *args, Error &err) const
     116             : {
     117             : 
     118           0 :     static const Error GENERAL_ERROR     = Error::fromCode(GPG_ERR_GENERAL);
     119           0 :     static const Error INV_NAME_ERROR    = Error::fromCode(GPG_ERR_INV_NAME);
     120           0 :     static const Error INV_EMAIL_ERROR   = Error::fromCode(GPG_ERR_INV_USER_ID);
     121           0 :     static const Error INV_COMMENT_ERROR = Error::fromCode(GPG_ERR_INV_USER_ID);
     122             : 
     123           0 :     if (needsNoResponse(status)) {
     124           0 :         return state();
     125             :     }
     126             : 
     127             :     using namespace GpgAddUserIDEditInteractor_Private;
     128             : 
     129           0 :     switch (state()) {
     130             :     case START:
     131           0 :         if (status == GPGME_STATUS_GET_LINE &&
     132           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     133           0 :             return COMMAND;
     134             :         }
     135           0 :         err = GENERAL_ERROR;
     136           0 :         return ERROR;
     137             :     case COMMAND:
     138           0 :         if (status == GPGME_STATUS_GET_LINE &&
     139           0 :                 strcmp(args, "keygen.name") == 0) {
     140           0 :             return NAME;
     141             :         }
     142           0 :         err = GENERAL_ERROR;
     143           0 :         return ERROR;
     144             :     case NAME:
     145           0 :         if (status == GPGME_STATUS_GET_LINE &&
     146           0 :                 strcmp(args, "keygen.email") == 0) {
     147           0 :             return EMAIL;
     148             :         }
     149           0 :         err = GENERAL_ERROR;
     150           0 :         if (status == GPGME_STATUS_GET_LINE &&
     151           0 :                 strcmp(args, "keygen.name") == 0) {
     152           0 :             err = INV_NAME_ERROR;
     153             :         }
     154           0 :         return ERROR;
     155             :     case EMAIL:
     156           0 :         if (status == GPGME_STATUS_GET_LINE &&
     157           0 :                 strcmp(args, "keygen.comment") == 0) {
     158           0 :             return COMMENT;
     159             :         }
     160           0 :         err = GENERAL_ERROR;
     161           0 :         if (status == GPGME_STATUS_GET_LINE &&
     162           0 :                 strcmp(args, "keygen.email") == 0) {
     163           0 :             err = INV_EMAIL_ERROR;
     164             :         }
     165           0 :         return ERROR;
     166             :     case COMMENT:
     167           0 :         if (status == GPGME_STATUS_GET_LINE &&
     168           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     169           0 :             return QUIT;
     170             :         }
     171           0 :         err = GENERAL_ERROR;
     172           0 :         if (status == GPGME_STATUS_GET_LINE &&
     173           0 :                 strcmp(args, "keygen.comment") == 0) {
     174           0 :             err = INV_COMMENT_ERROR;
     175             :         }
     176           0 :         return ERROR;
     177             :     case QUIT:
     178           0 :         if (status == GPGME_STATUS_GET_BOOL &&
     179           0 :                 strcmp(args, "keyedit.save.okay") == 0) {
     180           0 :             return SAVE;
     181             :         }
     182           0 :         err = GENERAL_ERROR;
     183           0 :         return ERROR;
     184             :     case ERROR:
     185           0 :         if (status == GPGME_STATUS_GET_LINE &&
     186           0 :                 strcmp(args, "keyedit.prompt") == 0) {
     187           0 :             return QUIT;
     188             :         }
     189           0 :         err = lastError();
     190           0 :         return ERROR;
     191             :     default:
     192           0 :         err = GENERAL_ERROR;
     193           0 :         return ERROR;
     194             :     }
     195             : }

Generated by: LCOV version 1.13